Created
June 3, 2019 04:11
-
-
Save zetavg/568b1a1ed56f0df28dd4c3f9085eedb9 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 useCallback(callback) { | |
const callbackRef = React.useRef(callback) | |
callbackRef.current = callback | |
const wrappedCallback = React.useMemo( | |
() => (...args) => callbackRef.current(...args), | |
[], | |
) | |
return wrappedCallback | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment