I made a hook like useUser. Now calling it bound mutate does not return new data in some components. Like in Login component it returns the data but in parent component it does not return new data. But api calls are happening.
Though removing getItem('token') solves the issue but removing that causes the api calls to always revalidate on focus and yields 400 error as after logout the token is not there. I am not sure if i am missing something here. Or there might be a logical error in my scenario.
This happens with just the case with login mutate. But after mutating with logout the data clears and reflects in parent component though.
const { data, mutate, error } = useSWR(() => getItem('token') ? '/users/me' : null, userFetcher, {
shouldRetryOnError: false,
});
const loading = !data && !error;
const loggedOut = error && error.status === 403;
return {
loading,
loggedOut,
user: data
mutate,
};
swr version: 0.3.5
PS: the codebase is with nextjs.
In our case upgrading to 0.3.6 fixed the problem
Yes. 0.3.6 fixed this.
Most helpful comment
In our case upgrading to 0.3.6 fixed the problem