@supuwoerc/toolkit
    Preparing search index...

    Variable throttleConst

    throttle: <T extends (...args: any[]) => any>(
        delay: number,
        callback: T,
        options?: ThrottleOptions,
    ) => __type<T> = _throttle

    Type Declaration

      • <T extends (...args: any[]) => any>(
            delay: number,
            callback: T,
            options?: ThrottleOptions,
        ): __type<T>
      • Throttle execution of a function. Especially useful for rate limiting execution of handlers on events like resize and scroll.

        Type Parameters

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

        Parameters

        • delay: number

          A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.

        • callback: T

          A function to be executed after delay milliseconds. The this context and all arguments are passed through, as-is, to callback when the throttled-function is executed.

        • Optionaloptions: ThrottleOptions

          An object to configure options.

          • noTrailing

            Optional, defaults to false. If noTrailing is true, callback will only execute every delay milliseconds while the throttled-function is being called. If noTrailing is false or unspecified, callback will be executed one final time after the last throttled-function call. (After the throttled-function has not been called for delay milliseconds, the internal counter is reset)

          • noLeading

            Optional, defaults to false. If noLeading is false, the first throttled-function call will execute callback immediately. If noLeading is true, the first the callback execution will be skipped. It should be noted that callback will never executed if both noLeading = true and noTrailing = true.

          • debounceMode

            If debounceMode is true (at begin), schedule callback to execute after delay ms. If debounceMode is false (at end), schedule callback to execute after delay ms.

        Returns __type<T>

        A new, throttled, function.

    The function to throttle

    Throttle interval in milliseconds

    Configuration options

    Whether to disable trailing execution

    Whether to disable leading execution

    Whether to enable debounce mode

    The throttled function

    const throttled = throttle(() => console.log('throttled'), 1000);
    window.addEventListener('resize', throttled);