Created
February 14, 2019 04:38
-
-
Save jquense/216e1f2cdcf89d5860da28199ce4a974 to your computer and use it in GitHub Desktop.
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
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