useDebounceFn
A hook that deal with the debounced function.
Examples
Default usage
Clicked count:0
Default usage
Frequent calls run, but the function is executed only after all the clicks have completed 500ms.
API
const { run, cancel, flush} = useDebounceFn( fn: (...args: any[]) => any, options?: Options);
const { run, cancel, flush} = useDebounceFn( fn: (...args: any[]) => any, options?: Options);
Params
| Property | Description | Type | Default |
|---|---|---|---|
| fn | The function to debounce. | (...args: any[]) => any | - |
| options | Config for the debounce behaviors. | Options | - |
Options
| Property | Description | Type | Default |
|---|---|---|---|
| wait | The number of milliseconds to delay. | number | 1000 |
| atBegin | Specify invoking on the leading edge of the timeout. | boolean | - |
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 |