100ms2000ms
Input value:
—
Debounced value:
—
useDebounce
A hook that delays updating a value until a specified time has passed since the last change. Useful for reducing the number of API calls or expensive calculations while a user is typing or interacting.
- Improves performance by reducing the frequency of expensive operations
- Perfect for search inputs, form validation, and API requests
- Configurable delay time to suit different use cases
Installation
The useDebounce hook is part of our UI library. You can import it directly from the hooks directory.
Usage
Here is how to use the useDebounce hook in your project:
React TSX
React TSX
API Reference
React TSX
Inputs
value
: The value to be debounceddelay
: The delay in milliseconds
Output
debouncedValue
: The debounced value that updates after the specified delay
Behavior
- Hook tracks the provided value but only updates the returned value after the delay
- Each change to the input value resets the delay timer
- The debounced value remains stable during rapid changes to the input value
- Cleans up any pending updates on component unmount