Skip to content

debounce

type: function
since: v2.6.0

The debounce function delays execution until no new calls are made for a specified duration.

Usage

import { debounce } from '@mustib/utils';
const fn = debounce(() => {
console.log('debounced');
}, 100);
fn();
fn();
fn(); // logs once after 100ms from the last call

Definition

function debounce<T extends Func = Func>(func: T, ms = 100): T { }

Parameters

  1. func
    type func = Function;
    • Function to debounce.
  2. ms
    type ms = number;
    /* default value */
    const ms = 100;
    • Delay in milliseconds after the most recent call.

Returns

type T = Function;
  • Debounced function with the same call signature.