Tweakr
    Preparing search index...

    Function debounce

    • Creates a debounced version of a function that delays invoking fn until after delay milliseconds have elapsed since the last call.

      Type Parameters

      • T extends (...args: any[]) => void

      Parameters

      • fn: T

        The function to debounce.

      • delay: number = 300

        The number of milliseconds to delay (default: 300ms).

      Returns (...args: Parameters<T>) => void

      A debounced function.

      const log = (msg: string) => console.log(msg);
      const debouncedLog = debounce(log, 200);
      debouncedLog("Hello"); // will run 200ms after the last call

      1.1.0