Skip to main content

Function: debounce()

debounce<T>(function_: (...arguments_: T) => void, wait: number): (...arguments_: T) => void

Defined in: src/stores/utils.ts:124

Debounce utility for store actions with automatic cleanup.

Type Parametersโ€‹

Tโ€‹

T extends unknown[]

Parametersโ€‹

function_โ€‹

(...arguments_: T) => void

Function to debounce

waitโ€‹

number

Wait time in milliseconds before executing

Returnsโ€‹

Debounced version of the input function

(...arguments_: T): void

Parametersโ€‹

arguments_โ€‹

...T

Returnsโ€‹

void

Remarksโ€‹

This utility prevents rapid successive calls to expensive operations like API requests or state updates. It uses a Map to track timeouts per unique argument combination, allowing different argument sets to be debounced independently.

Exampleโ€‹

const debouncedSave = debounce(saveSettings, 500);
debouncedSave(newSettings); // Will only execute after 500ms of no new calls