Created
June 3, 2026 09:58
-
-
Save n4bb12/979cfe64dec7f5fd440475d732bb9f50 to your computer and use it in GitHub Desktop.
useEventCallback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useCallback, useRef } from "react" | |
| /** | |
| * Stable callback identity with always-fresh implementation. | |
| * @see https://github.com/facebook/react/issues/14099 | |
| */ | |
| export function useEventCallback<F extends (...args: never[]) => unknown>(fn: F): F { | |
| const ref = useRef(fn) | |
| ref.current = fn | |
| return useCallback(((...args) => ref.current.apply(undefined, args)) as F, []) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment