Skip to content

Instantly share code, notes, and snippets.

@JLarky
Created September 15, 2020 22:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JLarky/f6379ac39d00a1f71675a677a877fb94 to your computer and use it in GitHub Desktop.
Save JLarky/f6379ac39d00a1f71675a677a877fb94 to your computer and use it in GitHub Desktop.
import React from 'react';
function useCallbackOnce(callback: () => void) {
const once = React.useRef(false);
return React.useCallback(() => {
if (!once.current) {
once.current = true;
callback();
}
}, [callback]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment