T
TanStack9mo ago
genetic-orange

Simple question regarding redirecting on error

I have a simple question. Take the following code:
const { isError } = useQuery(getUserInfo);
if (isError) {
return <Navigate to="/signup" />;
}
const { isError } = useQuery(getUserInfo);
if (isError) {
return <Navigate to="/signup" />;
}
This works, but it tries three times so it actually takes a few seconds to redirect to /signup if the user is logged out (401). Can I detect a 401 the first time and redirect right away?
2 Replies
sensitive-blue
sensitive-blue9mo ago
Important Defaults | TanStack Query React Docs
Out of the box, TanStack Query is configured with aggressive but sane defaults. Sometimes these defaults can catch new users off guard or make learning/debugging difficult if they are unknown by the u...
Query Retries | TanStack Query React Docs
When a useQuery query fails (the query function throws an error), TanStack Query will automatically retry the query if that query's request has not reached the max number of consecutive retries (defau...
genetic-orange
genetic-orangeOP9mo ago
thanks!

Did you find this page helpful?