(fn?: T)
| 18 | const useEarlyEffect = React['useInsertionEffect'] ?? useLayoutEffect; |
| 19 | |
| 20 | export function useEffectEvent<T extends Function>(fn?: T): T { |
| 21 | const ref = useRef<T | null | undefined>(null); |
| 22 | useEarlyEffect(() => { |
| 23 | ref.current = fn; |
| 24 | }, [fn]); |
| 25 | // @ts-ignore |
| 26 | return useCallback<T>((...args) => { |
| 27 | const f = ref.current!; |
| 28 | return f?.(...args); |
| 29 | }, []); |
| 30 | } |
no outgoing calls