( fn: ( ...args: A ) => R )
| 10 | * Useful for preventing closures from capturing cached scope variables (avoiding the stale closure problem). |
| 11 | */ |
| 12 | export const useRefSafeCallback = <A extends Array<unknown>, R>( fn: ( ...args: A ) => R ): typeof fn => { |
| 13 | const callbackRef = useRef<typeof fn>(); |
| 14 | callbackRef.current = fn; |
| 15 | |
| 16 | return useCallback( |
| 17 | ( ...args: A ): R => ( callbackRef.current as typeof fn )( ...args ), |
| 18 | [] |
| 19 | ); |
| 20 | }; |
no outgoing calls
no test coverage detected
searching dependent graphs…