import { useRef } from 'react'; import type { useEffect, useLayoutEffect } from 'react'; type effectHookType = typeof useEffect | typeof useLayoutEffect; export const createUpdateEffect: (hook: effectHookType) => effectHookType = hook => (effect, deps) => { const isMounted = useRef(false); // for react-refresh hook(() => { return () => { isMounted.current = false; }; }, []); // eslint-disable-next-line consistent-return hook(() => { if (!isMounted.current) { isMounted.current = true; } else { return effect(); } }, deps); };