Skip to content

useThrottledCallback

useThrottledCallback<Args>(fn, delay, options?): ThrottledCallback<Args>

Defined in: src/hooks/useThrottledCallback/useThrottledCallback.ts:30

Wrap a function so it fires at most once per delay ms. With both leading and trailing enabled (the default), the first call fires immediately and the most recent call inside the window fires at its end. Set leading: false to defer the first call; set trailing: false to drop calls inside the window.

Typical use: drag handlers, scroll listeners, resize observers — places where the input rate exceeds the work rate and you want to bound the latter.

The wrapper identity is stable across renders.

Type Parameters

Args

Args extends unknown[]

Parameters

fn

(…args) => void

delay

number

options?

UseThrottledCallbackOptions = {}

Returns

ThrottledCallback<Args>

Example

const onPointerMove = useThrottledCallback(updateGuide, 16);