useThrottleFn

Commons
stable

Wraps a function so it executes at most once per wait milliseconds. The first call fires immediately; subsequent calls within the wait window are silently discarded. After the window expires the next call fires again immediately. Designed for scroll, resize, and pointer-move handlers where firing on every frame would be prohibitively expensive.

API

Signature

Full TypeScript signature sourced from the composable file.

typescript

useThrottleFn is a leading-edge throttle: the function fires on the FIRST call, then blocks subsequent calls for wait ms. This keeps UI responses instantaneous for the first interaction while capping the overall call rate.

API

Parameters

Input parameters accepted by this composable.

fn
required
(...args: T) => R
The function to throttle. Called immediately on the first invocation within each window. The return value is discarded — the wrapper always returns void.
wait
required
number
Throttle window in milliseconds. No call will execute within wait ms of the previous execution.

API

Return values

Properties and methods exposed by the composable return object.

(...args: T) => void
The throttled wrapper function. Call it as you would the original fn — excess calls within the wait window are dropped without side effects.

Usage

Examples

Ready-to-paste usage snippets.

Throttle a scroll handler to 16 ms

vue

Throttle a search-as-you-type input

vue