useDebounceutilities

useDebounce

NewSSR SAFE

Debounces a value or function for better performance.

$ pnpm dlx shadcn@latest add @byphongphan/use-debounce
Requires @byphongphan in components.json
utilities
Loading preview...

Installation

$ pnpm dlx shadcn@latest add @byphongphan/use-debounce
Requires @byphongphan in components.json

Usage

import { useState } from "react"import { useDebounce } from "@/shared/hooks"
export function SearchComponent() { const [searchTerm, setSearchTerm] = useState("") const debouncedSearch = useDebounce(searchTerm, 500)
// Trigger network search query only when debouncedSearch settles return ( <input value={searchTerm} onChange={(e) => setSearchTerm(e.target.value)} placeholder="Search docs..." /> )}

Props & Parameters

ParamTypeDefaultDescription
valueT—The rapidly changing input value to debounce.
delaynumber500Delay in milliseconds before updating debounced value.

Returns

ReturnTypeDescription
debouncedValueTThe debounced value updated only after the delay timer expires without changes.

Command Palette

Quick search and commands navigation