fn
throttle
v0.0.10testedInvokes a function at most once per `wait` ms
Example
ts
const onScroll = throttle(() => update(), 100);
window.addEventListener('scroll', onScroll);Signature
ts
export function throttle<T extends AnyFunction>(fn: T, wait: number | (() => number), options: ThrottleOptions ={ ... }Type Parameters
Textends AnyFunctionParameters
| Parameter | Type | Description |
|---|---|---|
fn | T | The function to throttle |
wait | number | (() => number) | Milliseconds to throttle to, or a getter resolved lazily on each call (useful for reactive windows) |
options? | ThrottleOptions | Leading/trailing edge behavior |
Returns
ThrottledFunction<T>The throttled function with `cancel()`, `flush()` and `pending()`