[solved] useQuery ignores `retry: false` when `refetchInterval` is set
Title pretty much says it all. Here is my query:As soon as I uncomment
refetchInterval: 5
, the query will indefinitely retry (as fast as it can) instead of simply stopping after the first error, which currently always happens (expected).
What am I doing wrong? I do want the query to refetch, but only if there were no errors.5 Replies
eastern-cyanOP•2mo ago
Query client config:
like-gold•2mo ago
retry and refetchInterval are not the same thing
retry defines how often query should retry running the queryFn before it goes into error state.
interval schedules a new run of the queryFn once it completes the previous run (including all retries) or otherwise gets data set
so yes, with zero retries and an interval of 5ms, you get a run every 5ms
with the default of 3 retries and exponential backoff and an interval of 5, you would get:
- run queryFn with 3 retries and pauses in between (that takes about 20-30s)
- wait 5ms
- run queryFn with 3 retries again
etc
so, not sure what you're trying to achieve but with that config, that's the expected behaviour
eastern-cyanOP•2mo ago
oh, i think i kind of understand.
what i'm trying to achieve:
- refetch every 5 seconds if the previous query was successful or there is no previous query (first query)
- if a query was unsuccessful, immediately go into error state and do not retry
like-gold•2mo ago
so
retry: false
and implement the refetchInterval
function to only set an interval if the query is in success stateeastern-cyanOP•2mo ago
got it. so i had 2 errors: thinking the value for
refetchInterval
was seconds where it's actually miliseconds, and also that specifying a refetchInterval ignores retry
by default and i need to implement that myself.
thanks a lot!
got it to work just like i need 👍