Skip to content

Instantly share code, notes, and snippets.

@zetavg
Created June 3, 2019 04:11
Show Gist options
  • Save zetavg/568b1a1ed56f0df28dd4c3f9085eedb9 to your computer and use it in GitHub Desktop.
Save zetavg/568b1a1ed56f0df28dd4c3f9085eedb9 to your computer and use it in GitHub Desktop.
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