Disable error component, or enable enable it to retry query.
Hey,
I got stuck with the problem that I want to have try again button to try to refetch query if it fails. I don't know how to do it using tanstack router because it is providing context inside error component, and i haven't found a way to disable errorComponent.
here is my route code:
how i'd like to do error handling inside Projects component, or if it is possible to do it I'm fine to placing ErrorMessage component to errorComponent inside route definition.
8 Replies
exotic-emerald•2y ago
is the issue that
ensureQueryData throws an error and this causes the error component to be rendered?
if yes, you could call it with throwOnError: falsedeep-jadeOP•2y ago
It doesn't work, I still get default
errorComponent from router
So what i figured out is:
and in Route:
But clicking on reset still does not fires any loading indicator, if it fails again from user perspective nothing has happend on clicking "reset"exotic-emerald•2y ago
it would be best if you can provide a minimal example on e.g. codesandbox
deep-jadeOP•2y ago
Oke, on it.
Here is what I have now: It does not work for some reason on code sandbox for me, but i download this code na locally it runs good.
https://codesandbox.io/p/devbox/cocky-carson-xvyg3s?file=%2Fsrc%2Froutes%2Findex.tsx%3A7%2C1
Ideally I would love to not having to use errorComponent and just handle error inside my component in this case
Post if it is possible.
What I don't like about current solutions is lack of any loading indicator after clicking on try again.exotic-emerald•2y ago
The problem is that
useSuspenseQuerythrows an error that is not caught by you and thus the error component is rendered.
In order to catch this error, you need an error boundary.
You could use something like this:
deep-jadeOP•2y ago
Thx for your answer it does work, and I can handle it inside component. But what about some loading indicator to show user that clicking on
try again actually did something. Now if request fails again it looks like button did nothing.exotic-emerald•2y ago
This is how you would do it using react-query's mechanism:
https://codesandbox.io/p/devbox/inspiring-field-rtjtsk
deep-jadeOP•2y ago
Thanks!