Skip to content
aq-ui
Back to HooksHook

Use Throttled Callback

Open-code aq-ui React hook for Use Throttled Callback.

Installation

pnpm dlx aq-ui@alpha add use-throttled-callback

API reference

Client module

Import the parts you need, then jump to an export for its contract.

View full source

Quick start

"use client"

import { useThrottledCallback } from "@/hooks/use-throttled-callback"

ThrottledFunction

typeSource L14

Type contract for ThrottledFunction.

type ThrottledFunction<T extends AnyFunction> = ((...args: Parameters<T>) => ReturnType<T> | undefined) & { … }

Members

NameType
cancel() => void
flush() => ReturnType<T> | undefined
pending() => boolean

ThrottleOptions

interfaceSource L9

Type contract for ThrottleOptions.

interface ThrottleOptions

Members

NameTypeDefault
leading?booleantrue
trailing?booleantrue

useThrottledCallback

functionSource L22

Open-code aq-ui React hook for Use Throttled Callback.

function useThrottledCallback<T extends AnyFunction>(callback: T, interval = 250, { leading = true, trailing = true }: ThrottleOptions = {}): ThrottledFunction<T>
Returns
ThrottledFunction<T>

Parameters

NameTypeDefault
callbackT—
interval?—250
options?ThrottleOptions{}

Registry dependencies

use-latest

Files

  • hooks/use-throttled-callback.ts

Source