Skip to content

Instantly share code, notes, and snippets.

@TotooriaHyperion
Created October 20, 2020 06:43
Show Gist options
  • Save TotooriaHyperion/56341793844e905c06ade9e219889389 to your computer and use it in GitHub Desktop.
Save TotooriaHyperion/56341793844e905c06ade9e219889389 to your computer and use it in GitHub Desktop.
useStableCallback
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