Created
March 12, 2020 07:08
-
-
Save numToStr/2bd4768d93d17c964c91656cf6ebfc5e 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
const useDebounce = () => { | |
let timeout = useRef<NodeJS.Timeout | null>(null); | |
return useCallback( | |
(fn: Function, wait: number) => (e: FormEvent) => { | |
e.preventDefault(); | |
timeout.current && clearTimeout(timeout.current); | |
timeout.current = setTimeout(() => { | |
fn(); | |
}, wait); | |
}, | |
[] | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment