Closed TheBoyWhoLivedd closed 10 months ago
Can I suggest that instead you do
try {
await sendLogout.unwrap()
navigate("/");
} catch {}
in your click handler?
const sendLogoutHandler = async () => {
try {
await sendLogout({}).unwrap();
navigate("/");
} catch (error) {
console.log(error);
}
};
This works and is my current workaround at the moment, but I'm still puzzled as to why the fulfilled
status does not trigger the effect or appear in the console. This is the knowledge gap I'm seeking to fill. Any insights would be much appreciated.
Hello, can I ask if you figured out why isSuccess=false still? Because I’m facing the same issue while following a tutorial.
Description
I am encountering an issue where a
useEffect
hook in my component is not responding to a 'fulfilled' status from a Redux Toolkit Query mutation. MyuseEffect
hook is supposed to navigate to the home route when the logout mutation (useSendLogoutMutation
) is fulfilled. The Redux store correctly updates the status to 'fulfilled', butuseEffect
seems to skip this status and does not trigger navigation.Steps to Reproduce
useSendLogoutMutation
to trigger a logout action.useEffect
hook inDashHeader
component is expected to catch this status change and navigate to the home route.Expected Behavior
When the
sendLogout
mutation's status changes to 'fulfilled', theuseEffect
should trigger and callnavigate("/")
.Actual Behavior
The
useEffect
detects the 'pending' and 'uninitialized' status but skips the 'fulfilled' status. As a result, the expected navigation does not occur.Attempts to Fix
resetApiState
.useEffect
call and status value.Code Snippet
// Redux Toolkit Query mutation
// Logout endpoint
Environment
@reduxjs/toolkit": "^2.0.1" React version: [18.2..0] Browser: Chrome Operating System: Windows 11