Created
October 20, 2020 06:43
-
-
Save TotooriaHyperion/56341793844e905c06ade9e219889389 to your computer and use it in GitHub Desktop.
useStableCallback
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
export const useStableCallback = <T extends (...args: any[]) => any>(cb: T): T => { | |
const cbRef = useRef(cb); | |
cbRef.current = cb; | |
return useCallback( | |
<T>((...args) => { | |
return cbRef.current?.(...args); | |
}), | |
[], | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment