Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useThrottleFn.md
1---2category: Utilities3related: refThrottled, refDebounced, useDebounceFn4---56# useThrottleFn78Throttle execution of a function. Especially useful for rate limiting execution of handlers on events like resize and scroll.910> Throttle is a spring that throws balls: after a ball flies out it needs some time to shrink back, so it cannot throw any more balls unless it's ready.1112## Usage1314```ts15import { useThrottleFn } from '@vueuse/core'1617const throttledFn = useThrottleFn(() => {18// do something, it will be called at most 1 time per second19}, 1000)2021useEventListener(window, 'resize', throttledFn)22```2324## Recommended Reading2526- [**Debounce vs Throttle**: Definitive Visual Guide](https://kettanaito.com/blog/debounce-vs-throttle)2728## Type Declarations2930```ts31/**32* Throttle execution of a function. Especially useful for rate limiting33* execution of handlers on events like resize and scroll.34*35* @param fn A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,36* to `callback` when the throttled-function is executed.37* @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.38* (default value: 200)39*40* @param [trailing] if true, call fn again after the time is up (default value: false)41*42* @param [leading] if true, call fn on the leading edge of the ms timeout (default value: true)43*44* @param [rejectOnCancel] if true, reject the last call if it's been cancel (default value: false)45*46* @return A new, throttled, function.47*48* @__NO_SIDE_EFFECTS__49*/50export declare function useThrottleFn<T extends FunctionArgs>(51fn: T,52ms?: MaybeRefOrGetter<number>,53trailing?: boolean,54leading?: boolean,55rejectOnCancel?: boolean,56): PromisifyFn<T>57```58