UNPKG

informed

Version:

A lightweight framework and utility for building powerful forms in React applications

28 lines (24 loc) 607 B
import { useRef, useEffect } from 'react'; // https://reactjs.org/docs/hooks-faq.html#can-i-run-an-effect-only-on-updates /** * * Acts as a react useEffect that does not run on first render. * * @example * useUpdateEffect(()=>{...}, [foo]) * 1st Render: NO CALL * foo changes: GETS CALLED * */ var useUpdateEffect = function useUpdateEffect(effect, deps) { var firstRef = useRef(true); var isFirstMount = firstRef.current; useEffect(function () { if (!isFirstMount) { return effect(); } else { firstRef.current = false; } }, deps); }; export { useUpdateEffect };