useThrottleFn
A hook that deal with the throttled function.
Overview
A hook that deal with the throttled function.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useThrottleFn.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useThrottleFn.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useThrottleFn.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useThrottleFn.jsonA hook that deal with the throttled function.
Examples
Default usage
API
const {
run,
cancel,
flush
} = useThrottleFn(
fn: (...args: any[]) => any,
options?: Options
);Params
| Property | Description | Type | Default |
|---|---|---|---|
| fn | The function to throttle. | (...args: any[]) => any | - |
| options | Config for the throttle behaviors | Options | - |
Options
| Property | Description | Type | Default |
|---|---|---|---|
| wait | The number of milliseconds to delay. | number | 1000 |
| leading | Specify invoking on the leading edge of the timeout. | boolean | true |
| trailing | Specify invoking on the trailing edge of the timeout. | boolean | true |
Result
| Property | Description | Type |
|---|---|---|
| run | Invoke and pass parameters to fn. | (...args: any[]) => any |
| cancel | Cancel the invocation of currently throttled function. | () => void |
| flush | Immediately invoke currently throttled function | () => void |