Skip to content

debounce

Creates a debounced function that delays invoking func until after delay milliseconds have elapsed since the last time the debounced function was invoked

Available since v1.9.0

import { debounce } from '@helpers4/function';
debounce<A extends unknown[], R>(func: function, delay: number): function
ParameterTypeDescription
funcfunctionThe function to debounce
delaynumberThe number of milliseconds to delay

function — The debounced function

The debounced function is only called once after the delay, even if invoked multiple times.

const fn = debounce((x: number) => console.log(x), 100);
fn(1);
fn(2);
fn(3);
// Only logs 3 after 100ms

View source on GitHub