function debounce<TFn>(fn, initialOptions): (...args) => void
function debounce<TFn>(fn, initialOptions): (...args) => void
Defined in: debouncer.ts:329
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:
• TFn extends AnyFunction
TFn
DebouncerOptions<TFn>
Function
...Parameters<TFn>
void
const debounced = debounce(() => {
saveChanges();
}, { wait: 1000 });
// Called repeatedly but executes at most once per second
inputElement.addEventListener('input', debounced);
const debounced = debounce(() => {
saveChanges();
}, { wait: 1000 });
// Called repeatedly but executes at most once per second
inputElement.addEventListener('input', debounced);
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.
