werkbank
    Preparing search index...

    Function useThrottleCallback

    • Returns a memoized throttled function.

      Type Parameters

      • Args extends unknown[]

        The arguments of the callback.

      • Return = unknown

        The return type of the callback.

      Parameters

      • cb: Callback<Args, Return>

        The function to throttle.

      • wait: number

        The throttle wait time in milliseconds.

      • dep: Dep = []

        Additional dependencies to recreate the throttled function.

      • options: ThrottleOptions | undefined = {}

        Throttle options (leading, trailing, etc.).

      Returns ThrottledFunction<Callback<Args, Return>>

      The throttled function.

      This hook wraps es-toolkit's throttle function. The callback is always up-to-date (via ref), so you don't need to include it in deps.

      const throttledScroll = useThrottleCallback((e) => {
      console.log("Scroll event", e);
      }, 100);