shadcn-ahooks
useRequest

Loading Delay

The API useRequest

Loading Delay

By setting options.loadingDelay, you can delay the time when loading turns to true, effectively prevent UI flashing.

const { loading, data } = useRequest(getUsername, {
   loadingDelay: 300
});

return <div>{ loading ? 'Loading...' : data }</div>

For example, in the above scenario, if getUsername returns within 300ms, loading will not become true, avoiding the page displays Loading....

You can quickly click the button in the example below to experience the effect

API

PropertyDescriptionTypeDefault
loadingDelaySet the delay time for loading to become truenumber0

Remark

options.loadingDelay supports dynamic changes.

On this page