react query not updating the `error` field on errors

I'm new to using react query and i'm using axios to fetch an REST API, the api is throwing a 4xx error but the error field of useQuery() is not updating, the same happens to isError isLoading stays true, so the application gets stuck on loading state forever. I've tried setting retry option to false or 0 but still doesn't work
3 Replies
erik.gh
erik.gh2y ago
could you please share some code?
rafaelsilva81
rafaelsilva81OP2y ago
my bad, should have provided with the description
const {
data: user,
isLoading,
error,
} = useQuery<UserResponse, AxiosError>('user', async () => {
return api.get('/user').then((res) => res.data);
});
const {
data: user,
isLoading,
error,
} = useQuery<UserResponse, AxiosError>('user', async () => {
return api.get('/user').then((res) => res.data);
});
I managed to fix this using the onError() option, but I found this strange... doesn't feel like it should work like this...
erik.gh
erik.gh2y ago
alright happy to hear that you fixed it yourself

Did you find this page helpful?