Hooks
useThrottle
Custom hook that throttles a callback function.
useThrottle
Usage
API
useThrottle
Custom hook that throttles a callback function.
Parameters
Name | Type | Description |
---|---|---|
fn | T | The callback function to throttle. |
options | ThrottleOptions | The configuration options. |
options.wait | number | The number of milliseconds to throttle invocations to. |
options.leading | boolean | Specify invoking on the leading edge of the timeout. |
options.trailing | boolean | Specify invoking on the trailing edge of the timeout. |
Returns
Name | Type | Description |
---|---|---|
callback | (...args: Parameters<T>) => void | A throttled version of the provided callback function. The throttled function will only execute at most once per every wait milliseconds. The callback function will be invoked with the same arguments as the original function, except that the last argument will be an object containing the cancel method, which can be called to cancel the execution of the throttled function. |
ThrottleOptions
Name | Type | Description |
---|---|---|
wait | number | The number of milliseconds to throttle invocations to. |
leading | boolean | Specify invoking on the leading edge of the timeout. |
trailing | boolean | Specify invoking on the trailing edge of the timeout. |