Size
0.29 kb
useThrottleFn
A throttle function, reactified.
Ensures that a function is only executed once in a specified time interval, no matter how many times it is invoked.
Installation
Usage
The useThrottleFn
hook accepts an interval in milliseconds and returns a throttle
function.
The first call executes right away, while subsequent calls within interval are throttled.
The final call is scheduled to run after the interval expires.
Override the default interval:
Use trailing: false
to avoid scheduling the last call:
Cancel pending executions:
When the component unmounts, pending executions are automatically canceled.
API Reference
UseThrottleFnOptions
The options of the useThrottleFn hook.
Prop | Type | Default |
---|---|---|
trailing? | boolean | true |
UseThrottleFnReturn
The return value of the useThrottleFn hook.
Prop | Type | Default |
---|---|---|
isPending | boolean | - |
cancel | () => void | - |
throttle | (callback: () => any, interval?: number | undefined) => void | - |