useRequest
Throttle
The API useRequest
Throttle
Enter the throttle mode by setting options.throttleWait. At this time, if run or runAsync is triggered frequently, the request will be executed with the throttle strategy.
const { data, run } = useRequest(getUsername, {
throttleWait: 300,
manual: true
});As in the example code above, if run is triggered frequently, it will only be executed once every 300ms.
You can quickly enter text in the input box below to experience the effect
API
Options
The usage and effects of all throttle property are the same as lodash.throttle
| Property | Description | Type | Default Value |
|---|---|---|---|
| throttleWait | Throttle wait time, in milliseconds. After setting, enter the throttle mode | number | - |
| throttleLeading | Execute the request before throttling starts | boolean | true |
| throttleTrailing | Execute the request after throttling ends | boolean | true |
Remark
options.throttleWait,options.throttleLeading,options.throttleTrailingsupport 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.