Typed HooksGetting StarteduseDebounce

useDebounce

A custom React hook that delays updating a value until after a specified delay.

⚠️ This content is not available in your language yet.

useDebounce is a useful custom React hook that implements debouncing functionality in React applications. Debouncing is a programming practice that limits the rate at which a function can execute, ensuring that time-intensive operations don't trigger too frequently.

This hook is particularly useful for scenarios like search inputs, where you want to delay API calls until the user has stopped typing, or for any situation where you need to delay processing a rapidly changing value.

Debounce Search

500ms
Input:
(empty)
Debounced:
(empty)
Results
Start typing to search

Installation

pnpm dlx shadcn@latest add https://shaddy-docs.vercel.app/r/use-debounce

API

useDebounce<T>(value: T, delay: number): T

Parameters

ParameterTypeDescription
valueTThe input value to debounce.
delaynumberThe delay in milliseconds before updating the debounced value.

Returns

  • Returns (T): The debounced value that updates only after the specified delay has passed without new changes.