Skip to main content

React Custom Hook: useDebounce

JavaScript

Debounce a fast-changing value, e.g. a search box.

A
Adaeze Okafor
Sample Aug 17, 2026
JavaScript · 8 lines
1
2
3
4
5
6
7
8
function useDebounce(value, delay) {
  const [debounced, setDebounced] = useState(value);
  useEffect(() => {
    const t = setTimeout(() => setDebounced(value), delay);
    return () => clearTimeout(t);
  }, [value, delay]);
  return debounced;
}
1 Fire 0 Learned something 1 Saved me time 1 Mind-blown
Sign in to react and star