Skip to content

Instantly share code, notes, and snippets.

@jquense
Created February 14, 2019 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jquense/216e1f2cdcf89d5860da28199ce4a974 to your computer and use it in GitHub Desktop.
Save jquense/216e1f2cdcf89d5860da28199ce4a974 to your computer and use it in GitHub Desktop.
function useEventCallback(fn) {
const ref = useRef(fn)
useLayoutEffect(() => {
ref.current = fn;
}, [fn]);
return useCallback(() => {
const fn = ref.current;
return fn();
}, [ref]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment