Go to repository

Function debounce

Returns a debounced function that delays execution until wait milliseconds have passed since its last invocation.

Type Parameters

Parameters

  • func: F

    The function to debounce.

  • wait: number = 100

    The number of milliseconds to wait before calling the function.

  • options: {
        immediate: boolean;
    } = ...

    Additional options for the function.

    • immediate: boolean

Returns DebouncedFunction<F>

A debounced function.

Debouncing postpones the execution until after a period of inactivity. It's ideal for tasks that don't need to execute repeatedly in quick succession, such as API calls based on user input.

Note that this cannot be converted to an arrow function, because the context of this is important during the call. Arrow functions significantly change the way the context is managed.