How to check if onErrorRetry is done with retrying? #1877
Unanswered
filipjakov
asked this question in
Q&A
Replies: 1 comment
-
Hi, Perhaps side stepping your question, but have you considered doing this instead? function App() {
const [count, setCount] = useState(0);
const { data, error } = useSWR("fails", () =>
Promise.reject(new Error("Always fails"))
);
useEffect(() => {
console.count("error");
setCount((c) => c + 1);
}, [error]);
useEffect(() => {
if (count === 3) window.alert("WOW");
}, [count]);
return (
<div className="App">
{count}
</div>
);
} Because I am thinking that every time a request fails, the error object it rejects to is a new reference, so you could just create a Regarding exponential back off, I think the default const expBackOff = attempt => Math.min(attempt > 1 ? 2 ** attempt * 1000 : 1000, 30 * 1000) // from react-query docs SWR's is a bit more terse, taken from here: const maxRetryCount = config.errorRetryCount
const currentRetryCount = opts.retryCount
// Exponential backoff
const timeout =
~~(
(Math.random() + 0.5) *
(1 << (currentRetryCount < 8 ? currentRetryCount : 8))
) * config.errorRetryInterval
if (!isUndefined(maxRetryCount) && currentRetryCount > maxRetryCount) {
return
}
setTimeout(revalidate, timeout, opts) That being said, my proposal wouldn't require you to change the default |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have the requirement in which, after a request fails 3 times, I should show a screen -> on that screen, there should be a CTA which triggers the whole cycle anew.
To achieve that, I have implemented the following code:
I have two questions:
isErr
state seems redundant)? Can i somehow infer thatonErrorRetry
is on pause from the existingdata
/error
/isValidating
return values?onErrorRetry
functionality?Beta Was this translation helpful? Give feedback.
All reactions