useDebounceSearch
Controls a search input with debouncing and a minimum character threshold. Only fires the onTimeOut callback after the user stops typing and the query meets the minimum length.
Signature
Params
| Param |
Type |
Default |
Description |
onTimeOut |
(query: string) => void |
— |
Called with the current query after delay ms of inactivity |
minQueryNumber |
number |
3 |
Minimum characters required before onTimeOut is invoked |
initialQuery |
string | null |
'' |
Initial value of the controlled input |
delay |
number |
800 |
Debounce delay in milliseconds |
Returns
| Property |
Type |
Description |
query |
string |
Current value of the search input |
handleChange |
(value: string) => void |
Pass to the input's onChange handler |
Usage
Notes
- Queries shorter than
minQueryNumber (but not empty) cancel any pending debounced call.
- Uses
throttle-debounce under the hood via a stable useRef to avoid resetting the timer on each render.
- Client-only (
'use client').