Skip to content

useDebounce

Debounced value for search and filters.

A React hook that delays propagating a fast-changing value until it settles. Ideal for search inputs, filters, and any expensive derived work.

Installation

pnpm dlx shadcn@latest add @frontal-labs/use-debounce

Usage

import { useDebounce } from "@/hooks/use-debounce";
import { useState } from "react";
 
function Search() {
  const [query, setQuery] = useState("");
  const debouncedQuery = useDebounce(query, 300);
 
  // Fetch or filter using debouncedQuery
  return <input value={query} onChange={(e) => setQuery(e.target.value)} />;
}

The timer resets on every change — only the settled value propagates after delay ms.

API

function useDebounce<T>(value: T, delay?: number): T;

Parameters

Return value

Returns the debounced value of the same type T.