Skip to content

throttle

throttle<T>(params): Throttled<T>

Defined in: async/throttle/index.ts:24

Creates a throttled version of a function that executes at most once every ms milliseconds.

T extends (…args) => unknown

ThrottleParams<T>

The parameters object

Throttled<T>

The throttled function with a .cancel() method

const throttledFn = throttle({ fn: onScroll, ms: 100 });
window.addEventListener("scroll", throttledFn);
throttledFn.cancel(); // cancel pending trailing call

rate limit, limit calls, scroll handler, resize handler

Error if fn is not a function

Error if ms is not a number or is negative