Last active
September 28, 2022 04:40
-
-
Save leifarriens/e06d6f721cfbfdd2c46617630b0a4eea to your computer and use it in GitHub Desktop.
This file contains 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 useDebounceEffect( | |
effect: React.EffectCallback, | |
delay = 500, | |
deps?: React.DependencyList | undefined, | |
) { | |
useEffect(() => { | |
const debounce = setTimeout(() => { | |
effect(); | |
}, delay); | |
return () => clearTimeout(debounce); | |
// eslint-disable-next-line react-hooks/exhaustive-deps | |
}, [delay, ...(deps || [])]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment