Pacer Docs
API Reference
Debouncer API Reference
- DebouncerOptions
- DebouncerState
- AsyncDebouncerOptions
- AsyncDebouncerState
- debounce
- asyncDebounce
- Debouncer
- AsyncDebouncer
- ReactDebouncerOptions
- ReactAsyncDebouncerOptions
- ReactDebouncer
- ReactAsyncDebouncer
- useDebouncer
- useDebouncedCallback
- useDebouncedState
- useDebouncedValue
- useAsyncDebouncer
- useAsyncDebouncedCallback
Throttler API Reference
- ThrottlerOptions
- ThrottlerState
- AsyncThrottlerOptions
- AsyncThrottlerState
- throttle
- asyncThrottle
- Throttler
- AsyncThrottler
- ReactThrottlerOptions
- ReactAsyncThrottlerOptions
- ReactThrottler
- ReactAsyncThrottler
- useThrottler
- useThrottledCallback
- useThrottledState
- useThrottledValue
- useAsyncThrottler
- useAsyncThrottledCallback
Rate Limiter API Reference
Queue API Reference
AI/LLM: This documentation page is available in plain markdown format at/pacer/latest/docs/reference/functions/debounce.md
Debouncer API Reference
debounce
ts
function debounce<TFn>(fn, initialOptions): (...args) => void;Defined in: debouncer.ts:328
Creates a debounced function that delays invoking the provided function until after a specified wait time. Multiple calls during the wait period will cancel previous pending invocations and reset the timer.
This synchronous version is lighter weight and often all you need - upgrade to asyncDebounce when you need promises, retry support, abort/cancel capabilities, or advanced error handling.
If leading option is true, the function will execute immediately on the first call, then wait the delay before allowing another execution.
State Management:
- Uses TanStack Store for reactive state management
- Use initialState to provide initial state values when creating the debouncer
- Use onExecute callback to react to function execution and implement custom logic
- The state includes canLeadingExecute, execution count, and isPending status
- State can be accessed via the underlying Debouncer instance's store.state property
- When using framework adapters (React/Solid), state is accessed from the hook's state property
Type Parameters#
TFn#
TFn extends AnyFunction
Parameters#
fn#
TFn
initialOptions#
DebouncerOptions<TFn>
Returns#
(...args) => void
Example#
ts
const debounced = debounce(() => {
saveChanges();
}, { wait: 1000 });
// Called repeatedly but executes at most once per second
inputElement.addEventListener('input', debounced);