@sensimods/utility-lab
    Preparing search index...

    Function throttle

    • Creates a throttled version of a function that only executes at most once per every limit milliseconds.

      The returned function includes a .cancel() method to reset the throttle state and clear any active timers.

      Type Parameters

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

      Parameters

      • func: T

        The function to throttle.

      • limit: number

        The number of milliseconds to wait between executions.

      Returns (...args: Parameters<T>) => void & { cancel: () => void }

      A throttled function with a .cancel() method.

      const handleScroll = throttle(() => console.log("Scrolling..."), 100);

      // To stop throttling and clear timers:
      handleScroll.cancel();