Skip to main content
Version: v2

Force Request

Forced request refers to a mechanism that bypasses the cache check and triggers a request. It is useful when the latest data needs to be obtained under certain conditions.

Force request with method​

Force request by calling the send function of the method instance, and passing true.

const response = await alovaInstance.Get('/api/user').send(true);

Force request in useHook​

Among the three core hooks of useRequest/useWatcher/useFetcher, force request parameters are supported.

// useRequest
useRequest(todoListGetter, {
force: true
});

// useWatcher
useWatcher(todoListGetter, [page], {
force: true
});

// useFetcher
useFetcher({
force: true
});

Dynamically set force value​

In actual situations, we often need to set whether to force the request to be sent based on different situations. In this case, force can be set to a function, which will also receive parameters passed in from the send function. Please read the receive params for details

useRequest(todoListGetter, {
force: isForce => {
return isForce;
}
});

// useWatcher
useWatcher(todoListGetter, [page], {
force: isForce => {
return isForce;
}
});

// useFetcher
useFetcher({
force: isForce => {
return isForce;
}
});

useFetcher is a useHook for data fetching, which will be discussed in the Data Fetching chapter later.