The useDebounce hook delays updating a value until after a specified delay period has passed without changes. This is useful for optimizing performance in scenarios like search inputs, API calls, or expensive computations.
Used in components: Input, Textarea (for character count updates), EmojiPicker (for search filtering)
Most of the time you don't need to use this hook directly. The Input and Textarea components already use it internally when `maxLength` is set. Use this hook when you need custom debouncing logic in your own components.
- Delays value updates until user stops typing
- Prevents excessive API calls or computations
- Simple and lightweight implementation
- Works with any value type
Debounce a search input to avoid excessive API calls:
Optimize API requests by debouncing user input:
Debounce expensive calculations:
Returns the debounced value that updates only after the specified delay period has passed without changes.
- Choose appropriate delay: 300-500ms for search, 100-200ms for UI feedback
- Combine with useMemo: Debounce input, then memoize expensive computations
- Cancel pending requests: Clean up API calls when component unmounts