When my useQuery is in error state, it seems to auto refetch.
Is this an accurate assumption? What is the interval time at which it refetches? How can this be controlled?
3 Replies
quickest-silver•2y ago
Your answer is probably here: https://tanstack.com/query/latest/docs/framework/react/guides/query-retries
Query Retries | TanStack Query 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 (defaults to 3) or a function is provided to determine if a retry is allowed.
You can configure retries both on a global level and an individual query ...
quickest-silver•2y ago
And RQ is agnostic so maybe whatever you use to fetch (axios, ky, etc) is the culprit
adverse-sapphireOP•2y ago
Thank you! I think what's happening is my staleTime interval is kicking in and error goes to null and it refetches
Is it possible to use a different refetchInterval while in error state?
If I do a
const { error } = useQuery({ queryKey: '.....', enabled: false, notifyOnChangeProps: ['error'] })
will it update when it gets error even though its enabled is false? I dont want this to affect gc time or stale time, just need the error, so in next useQuery I can determine refetchInterval based on if error or not
Oh I just found refetchInterval can take a function which gets the query
- so will use that, thanks!