Created
September 20, 2019 18:34
-
-
Save chestercharles/ed5f67b6b2fecde1854986bd64d4f70c to your computer and use it in GitHub Desktop.
Hook to throttle a callback function
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 function useThrottledCallback(cb, ms) { | |
| const [callable, setCallable] = useState(true); | |
| return () => { | |
| if (callable) { | |
| cb(); | |
| setCallable(false); | |
| setTimeout(() => setCallable(true), ms); | |
| } | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment