File: Debouncer.md | Updated: 11/15/2025
Search...
+ K
Auto
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide
Documentation
Framework
React
Version
Latest
Search...
+ K
Menu
Getting Started
Guides
API Reference
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference
Batcher API Reference
Debouncer Examples
Throttler Examples
Rate Limiter Examples
Queue Examples
Batcher Examples
TanStack Query Examples
Framework
React
Version
Latest
Menu
Getting Started
Guides
API Reference
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference
Batcher API Reference
Debouncer Examples
Throttler Examples
Rate Limiter Examples
Queue Examples
Batcher Examples
TanStack Query Examples
On this page
Copy Markdown
Class: Debouncer<TFn>
=====================
Defined in: debouncer.ts:142
A class that creates a debounced function.
Debouncing ensures that a function is only executed after a certain amount of time has passed since its last invocation. This is useful for handling frequent events like window resizing, scroll events, or input changes where you want to limit the rate of execution. This synchronous version is lighter weight and often all you need - upgrade to AsyncDebouncer when you need promises, retry support, abort/cancel capabilities, or advanced error handling.
The debounced function can be configured to execute either at the start of the delay period (leading edge) or at the end (trailing edge, default). Each new call during the wait period will reset the timer.
State Management:
ts
const debouncer = new Debouncer((value: string) => {
saveToDatabase(value);
}, { wait: 500 });
// Will only save after 500ms of no new input
inputElement.addEventListener('input', () => {
debouncer.maybeExecute(inputElement.value);
});
const debouncer = new Debouncer((value: string) => {
saveToDatabase(value);
}, { wait: 500 });
// Will only save after 500ms of no new input
inputElement.addEventListener('input', () => {
debouncer.maybeExecute(inputElement.value);
});
Type Parameters
---------------
### TFn
TFn extends AnyFunction
Constructors
------------
### Constructor
ts
new Debouncer<TFn>(fn, initialOptions): Debouncer<TFn>;
new Debouncer<TFn>(fn, initialOptions): Debouncer<TFn>;
Defined in: debouncer.ts:150
TFn
DebouncerOptions <TFn>
Debouncer<TFn>
ts
fn: TFn;
fn: TFn;
Defined in: debouncer.ts:151
ts
key: string | undefined;
key: string | undefined;
Defined in: debouncer.ts:146
ts
options: DebouncerOptions<TFn>;
options: DebouncerOptions<TFn>;
Defined in: debouncer.ts:147
ts
readonly store: Store<Readonly<DebouncerState<TFn>>>;
readonly store: Store<Readonly<DebouncerState<TFn>>>;
Defined in: debouncer.ts:143
ts
cancel(): void;
cancel(): void;
Defined in: debouncer.ts:281
Cancels any pending execution
void
ts
flush(): void;
flush(): void;
Defined in: debouncer.ts:264
Processes the current pending execution immediately
void
ts
maybeExecute(...args): void;
maybeExecute(...args): void;
Defined in: debouncer.ts:217
Attempts to execute the debounced function If a call is already in progress, it will be queued
...Parameters<TFn>
void
ts
reset(): void;
reset(): void;
Defined in: debouncer.ts:292
Resets the debouncer state to its default values
void
ts
setOptions(newOptions): void;
setOptions(newOptions): void;
Defined in: debouncer.ts:171
Updates the debouncer options
#### Parameters ##### newOptions
Partial<DebouncerOptions <TFn>>
void
