Skip to content

Instantly share code, notes, and snippets.

@alexeyraspopov
Last active June 2, 2022 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexeyraspopov/d1b80d16ab7c35aef614596215ebd659 to your computer and use it in GitHub Desktop.
Save alexeyraspopov/d1b80d16ab7c35aef614596215ebd659 to your computer and use it in GitHub Desktop.
function useDebouncedValue(value, delay) {
let [debounced, setDebounced] = useState(value);
useEffect(() => {
let timer = setTimeout(setDebounced, delay, value);
return () => clearTimeout(timer);
}, [delay, value]);
return debounced;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment