Performance

useDebounce

Debounce a value to optimize frequent updates and function calls.

Overview

useDebounce delays the execution of a function or value update until after the user has stopped triggering changes for a specified duration. Perfect for search inputs, API calls, and heavy computations.

Hook Implementation

The complete hook source code

useDebouncetypescript
jsx

Usage Example

See how to use this hook in your components

Example Componenttypescript
jsx

API Reference

Parameters

value: T

The value to debounce

delay: number

Delay in milliseconds (default: 500)

Returns

T - The debounced value

Best Practices

  • Always memoize or stabilize dependencies to prevent unnecessary re-renders
  • Consider the performance implications when dealing with frequently updated values
  • Test edge cases like null values, rapid updates, and component unmounting