Skip to content

Instantly share code, notes, and snippets.

@normanzb
Created October 21, 2020 17:22
Show Gist options
  • Save normanzb/93f838eae71064f7551822706a7c4909 to your computer and use it in GitHub Desktop.
Save normanzb/93f838eae71064f7551822706a7c4909 to your computer and use it in GitHub Desktop.
const useCallbackWithAutoScopeRenewal = (callback, triggers) => {
const callbackWithLatestScope = useCallback(callback, triggers)
const callbackContainer = useRef({})
callbackContainer.current = callbackWithLatestScope
return (...args) => {
return callbackContainer.current(...args)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment