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

Signature TypeScript complète extraite du fichier du composable.

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

Paramètres

Paramètres d'entrée acceptés par ce composable.

fn
requis
(...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
requis
number
Throttle window in milliseconds. No call will execute within wait ms of the previous execution.

API

Valeurs de retour

Propriétés et méthodes exposées par l'objet retourné par le composable.

(...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

Exemples

Extraits de code prêts à coller.

Throttle a scroll handler to 16 ms

vue

Throttle a search-as-you-type input

vue