useDebounceFn
A hook that deal with the debounced function.
Overview
A hook that deal with the debounced function.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDebounceFn.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDebounceFn.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDebounceFn.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDebounceFn.jsonA hook that deal with the debounced function.
Examples
Default usage
API
const {
run,
cancel,
flush
} = useDebounceFn(
fn: (...args: any[]) => any,
options?: Options
);Params
| Property | Description | Type | Default |
| -- | | - |
| wait | The number of milliseconds to delay. | number | 1000 |
| leading | Specify invoking on the leading edge of the timeout. | boolean | false |
| trailing | Specify invoking on the trailing edge of the timeout. | boolean | true |
| maxWait | The maximum time func is allowed to be delayed before it’s invoked. | number | - |
Result
| Property | Description | Type |
| -- | | - |
| run | invoke and pass parameters to fn. | (...args: any[]) => any |
| cancel | Cancel the invocation of currently debounced function. | () => void |
| flush | Immediately invoke currently debounced function. | () => void |