UNPKG

ahooks

Version:
14 lines (13 loc) 480 B
import { useRef } from 'react'; import useEffectWithTarget from './useEffectWithTarget'; import { depsEqual } from './depsEqual'; const useDeepCompareEffectWithTarget = (effect, deps, target) => { const ref = useRef(undefined); const signalRef = useRef(0); if (!depsEqual(deps, ref.current)) { signalRef.current += 1; } ref.current = deps; useEffectWithTarget(effect, [signalRef.current], target); }; export default useDeepCompareEffectWithTarget;