Skip to content
usefy

useDebounce

Timing & async

A feature-rich React hook for debouncing values with leading/trailing edge and maxWait support

Install

$ npm install @usefy/use-debounce

Quick start

useDebounce.tsx
import { useDebounce } from "@usefy/use-debounce";

function SearchInput() {
  const [query, setQuery] = useState("");
  const debouncedQuery = useDebounce(query, 300);

  useEffect(() => {
    if (debouncedQuery) {
      searchAPI(debouncedQuery);
    }
  }, [debouncedQuery]);

  return (
    <input
      type="text"
      value={query}
      onChange={(e) => setQuery(e.target.value)}
      placeholder="Search..."
    />
  );
}

API reference

useDebounce<T>(value, delay?, options?)

A hook that returns a debounced version of the provided value.

Parameters

ParameterTypeDefaultDescription
valueTThe value to debounce
delaynumber500The debounce delay in milliseconds
optionsUseDebounceOptions{}Additional configuration options

Options

OptionTypeDefaultDescription
leadingbooleanfalseUpdate on the leading edge (first call)
trailingbooleantrueUpdate on the trailing edge (after delay)
maxWaitnumberMaximum time to wait before forcing an update

Returns

TypeDescription
TThe debounced value

Go deeper

This page is the quick reference. For every example, prop, and edge case, read the full README — or open Storybook to change props live.

More in timing & async