UNPKG

ahooks

Version:
12 lines (11 loc) 384 B
import { useRef } from 'react'; import { depsEqual } from '../utils/depsEqual'; export const createDeepCompareEffect = (hook) => (effect, deps) => { const ref = useRef(undefined); const signalRef = useRef(0); if (deps === undefined || !depsEqual(deps, ref.current)) { signalRef.current += 1; } ref.current = deps; hook(effect, [signalRef.current]); };