useRequest
Debounce
The API useRequest
Debounce
Enter the debounce mode by setting options.debounceWait. At this time, if run or runAsync is triggered frequently, the request will be executed with the debounce strategy.
const { data, run } = useRequest(getUsername, {
debounceWait: 300,
manual: true
});As in the example code above, if run is triggered frequently, it will only wait for 300ms to execute after the last trigger.
You can quickly enter text in the input box below to experience the effect
API
Options
The usage and effect of all debounce property are the same as lodash.debounce
| Property | Description | Type | Default Value |
|---|---|---|---|
| debounceWait | Debounce delay time, in milliseconds. After setting, enter the debounce mode | number | - |
| debounceLeading | Execute the request before the delay starts | boolean | false |
| debounceTrailing | Execute the request after the delay ends | boolean | true |
| debounceMaxWait | The maximum time request is allowed to be delayed before it’s executed | number | - |
| pollingIntervalWhen | pollingIntervalWhen is used together with debounce options, it specifies when to start polling | (data, params) => number | boolean | - |
Remark
options.debounceWait,options.debounceLeading,options.debounceTrailing,options.debounceMaxWait,options.pollingIntervalWhensupport dynamic changes.runAsyncwill return aPromisewhen it is actually executed. When it is not executed, there will be no return.cancelcan abort a function waiting to be executed.