Created
September 15, 2020 22:19
-
-
Save JLarky/f6379ac39d00a1f71675a677a877fb94 to your computer and use it in GitHub Desktop.
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
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