Skip to content

Instantly share code, notes, and snippets.

@ryanto
Last active May 24, 2021 14:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ryanto/095c8e06d03f9fb1928326419db98dac to your computer and use it in GitHub Desktop.
Save ryanto/095c8e06d03f9fb1928326419db98dac to your computer and use it in GitHub Desktop.
function useDebounced(value, timeout) {
let [debouncedValue, setDebouncedValue] = useState(value)
useEffect(() => {
let timeoutId = setTimeout(() => {
setDebouncedValue(value)
}, timeout)
return () => {
clearTimeout(timeoutId)
}
}, [value, timeout])
return debouncedValue
}
@weironiottan
Copy link

On Line 7, I believe there is a typo. the delay should be timeout. Loved the video btw!

@ryanto
Copy link
Author

ryanto commented May 24, 2021

Nice catch @weironiottan! That's all fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment