Tweakr
    Preparing search index...

    Function throttle

    • Creates a throttled function that only invokes fn at most once per limit milliseconds.

      Type Parameters

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

      Parameters

      • fn: T

        The function to throttle.

      • limit: number = 300

        Minimum time in milliseconds between calls (default: 300ms).

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

      A throttled version of fn.

      const log = (msg: string) => console.log(msg);
      const throttledLog = throttle(log, 1000);
      window.addEventListener("scroll", () => throttledLog("scrolling"));

      1.1.0