Skip to main content

debounce

Callable

  • debounce<T>(fn: T, ms: number): (...args: Parameters<T>) => void

  • Returns a new function that will only be executed after being idle for a certain amount of time. Useful for reducing the number of expensive function calls.

    @example
    const debouncedFn = debounce(() => {
    console.log('Hello')
    }, 1000)

    debouncedFn()
    debouncedFn() // Logs 'Hello' after 1 second

    Type parameters

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

    Parameters

    • fn: T

      The function to execute.

    • ms: number

      The amount of time to wait before executing the function.

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

    A new function that will only be executed after being idle for a certain amount of time.

      • (...args: Parameters<T>): void
      • Parameters

        • rest...args: Parameters<T>

        Returns void