(hook)
| 7 | |
| 8 | export const createUpdateEffect: (hook: EffectHookType) => EffectHookType = |
| 9 | (hook) => (effect, deps) => { |
| 10 | const isMounted = useRef(false); |
| 11 | |
| 12 | // for react-refresh |
| 13 | hook(() => { |
| 14 | return () => { |
| 15 | isMounted.current = false; |
| 16 | }; |
| 17 | }, []); |
| 18 | |
| 19 | hook(() => { |
| 20 | if (!isMounted.current) { |
| 21 | isMounted.current = true; |
| 22 | } else { |
| 23 | return effect(); |
| 24 | } |
| 25 | }, deps); |
| 26 | }; |