📄 tanstack/pacer/latest/docs/reference/classes/Debouncer

File: Debouncer.md | Updated: 11/15/2025

Source: https://tanstack.com/pacer/latest/docs/reference/classes/Debouncer



TanStack

Pacer v0v0

Search...

+ K

Auto

Log In

TanStack StartRC

Docs Examples GitHub Contributors

TanStack Router

Docs Examples GitHub Contributors

TanStack Query

Docs Examples GitHub Contributors

TanStack Table

Docs Examples Github Contributors

TanStack Formnew

Docs Examples Github Contributors

TanStack DBbeta

Docs Github Contributors

TanStack Virtual

Docs Examples Github Contributors

TanStack Paceralpha

Docs Examples Github Contributors

TanStack Storealpha

Docs Examples Github Contributors

TanStack Devtoolsalpha

Docs Github Contributors

More Libraries

Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide

Documentation

Framework

React logo

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 logo

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

Debouncer

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:

  • 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 debouncer.store.state when using the class directly
  • When using framework adapters (React/Solid), state is accessed from debouncer.state

Example
-------

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

#### Parameters ##### fn

TFn

##### initialOptions

DebouncerOptions <TFn>

#### Returns

Debouncer<TFn>

Properties
----------
### fn

ts

fn: TFn;


fn: TFn;

Defined in: debouncer.ts:151


### key

ts

key: string | undefined;


key: string | undefined;

Defined in: debouncer.ts:146


### options

ts

options: DebouncerOptions<TFn>;


options: DebouncerOptions<TFn>;

Defined in: debouncer.ts:147


### store

ts

readonly store: Store<Readonly<DebouncerState<TFn>>>;


readonly store: Store<Readonly<DebouncerState<TFn>>>;

Defined in: debouncer.ts:143

Methods
-------
### cancel()

ts

cancel(): void;


cancel(): void;

Defined in: debouncer.ts:281

Cancels any pending execution

#### Returns

void


### flush()

ts

flush(): void;


flush(): void;

Defined in: debouncer.ts:264

Processes the current pending execution immediately

#### Returns

void


### maybeExecute()

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 ##### args

...Parameters<TFn>

#### Returns

void


### reset()

ts

reset(): void;


reset(): void;

Defined in: debouncer.ts:292

Resets the debouncer state to its default values

#### Returns

void


### setOptions()

ts

setOptions(newOptions): void;


setOptions(newOptions): void;

Defined in: debouncer.ts:171

Updates the debouncer options

#### Parameters ##### newOptions

Partial<DebouncerOptions <TFn>>

#### Returns

void

Edit on GitHub

asyncDebounce

AsyncDebouncer

Partners Become a Partner

Code RabbitCode Rabbit CloudflareCloudflare AG GridAG Grid NetlifyNetlify NeonNeon WorkOSWorkOS ClerkClerk ConvexConvex ElectricElectric SentrySentry PrismaPrisma StrapiStrapi UnkeyUnkey

scarf analytics