Debouncer API Reference
- DebouncerOptions
- DebouncerState
- AsyncDebouncerOptions
- AsyncDebouncerState
- debounce
- asyncDebounce
- Debouncer
- AsyncDebouncer
- PreactDebouncerOptions
- PreactAsyncDebouncerOptions
- PreactDebouncer
- PreactAsyncDebouncer
- useDebouncer
- useDebouncedCallback
- useDebouncedState
- useDebouncedValue
- useAsyncDebouncer
- useAsyncDebouncedCallback
Throttler API Reference
- ThrottlerOptions
- ThrottlerState
- AsyncThrottlerOptions
- AsyncThrottlerState
- throttle
- asyncThrottle
- Throttler
- AsyncThrottler
- PreactThrottlerOptions
- PreactAsyncThrottlerOptions
- PreactThrottler
- PreactAsyncThrottler
- useThrottler
- useThrottledCallback
- useThrottledState
- useThrottledValue
- useAsyncThrottler
- useAsyncThrottledCallback
Rate Limiter API Reference
Queue API Reference
useDebouncedCallback
function useDebouncedCallback<TFn>(fn, options): (...args) => void;Defined in: debouncer/useDebouncedCallback.ts:42
A Preact hook that creates a debounced version of a callback function. This hook is essentially a wrapper around the basic debounce function that is exported from @tanstack/pacer, but optimized for Preact with reactive options and a stable function reference.
The debounced function will only execute after the specified wait time has elapsed since its last invocation. If called again before the wait time expires, the timer resets and starts waiting again.
This hook provides a simpler API compared to useDebouncer, making it ideal for basic debouncing needs. However, it does not expose the underlying Debouncer instance.
For advanced usage requiring features like:
- Manual cancellation
- Access to execution counts
- Custom useCallback dependencies
Consider using the useDebouncer hook instead.
Type Parameters#
TFn#
TFn extends AnyFunction
Parameters#
fn#
TFn
options#
PreactDebouncerOptions<TFn, { }>
Returns#
(...args) => void
Example#
// Debounce a search handler
const handleSearch = useDebouncedCallback((query: string) => {
fetchSearchResults(query);
}, {
wait: 500 // Wait 500ms between executions
});
// Use in an input
<input
type="search"
onChange={(e) => handleSearch(e.target.value)}
/>