Why doesn’t my second call to personDataSend
set isLoading
value work in the RTK Query mutation query? When you do onClick for the first time, isLoading
is true, but on the second click, it is not, and on the second one, the value remains false.
const [
getDriverLicenseByPin,
{ data, isLoading },
] = useLazyGetDriverLicenseByPinQuery();
const personDataSend = (values) => {
getDriverLicenseByPin({
pin: values.Pin,
driverLicenseNumber: values.DriverLicenseNumber,
});
};
2
Answers
RTK will cache the result. If you want to re-fetch you will have to invalidate that part of your store first.
https://redux-toolkit.js.org/rtk-query/usage/automated-refetching
Queries only load once really, e.g. when no data has been cached yet. You likely want to use the
isFetching
status which is true whenever the query is actively fetching.See useLazyQuery:
Update your logic to also reference the
isFetching
status, which should be true when the query endpoint is re-triggered/re-fetching.