UMD Web Utilities Library
    Preparing search index...

    Function debounce

    • Debounces a function to limit how often it can be called

      Creates a debounced version of the provided function that delays execution until after the specified wait time has elapsed since the last call. Useful for optimizing performance of expensive operations triggered by frequent events (e.g., window resize, scroll, input).

      Type Parameters

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

      Parameters

      • callback: T

        The function to debounce

      • wait: number = 50

        The number of milliseconds to delay (default: 50ms)

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

      The debounced function

      const handleResize = () => {
      console.log('Window resized');
      };

      const debouncedResize = debounce(handleResize, 200);
      window.addEventListener('resize', debouncedResize);