Last active
October 26, 2024 03:14
-
-
Save ryanto/095c8e06d03f9fb1928326419db98dac 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
function useDebounced(value, timeout) { | |
let [debouncedValue, setDebouncedValue] = useState(value) | |
useEffect(() => { | |
let timeoutId = setTimeout(() => { | |
setDebouncedValue(value) | |
}, timeout) | |
return () => { | |
clearTimeout(timeoutId) | |
} | |
}, [value, timeout]) | |
return debouncedValue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice catch @weironiottan! That's all fixed!