How do I show a toast from loader error?
Previously I used
useEffect to make fetch data and if there was any error used catch to show a toast
But now I am able to console log the errro but I don't see any toast
13 Replies
xenial-blackβ’11mo ago
a full example would be helpful. can you please fork one of the stackblitz examples?
afraid-scarletOPβ’11mo ago
Sorry it has nothing to do with tanstack router. It was my fault. It's working now. Since Tanstack requires new file base route setup. I forgot to copy the Toast.
A quick question. Do I also need to wrap
getData in try catch? If I don't wrap in try catch then I get error on browser console. Then what's the use of onCatch or onError on the doc it says for onError
The routeOptions.onError option is a function that is called when an error occurs during the route loading.and
The routeOptions.onCatch option is a function that is called whenever an error was caught by the router's CatchBoundary.index.tsx Here is code sand box link: https://codesandbox.io/p/github/watery-desert/tanstack-toast-issue/main?import=true and error firs the uncaught error obviously Then this one
xenial-blackβ’11mo ago
these errors are caught but still logged by react
unfortunately...
so the onCatch method will still be called
afraid-scarletOPβ’11mo ago
so I should remove
onError and onCatch and use try catch?xenial-blackβ’11mo ago
it depends really
afraid-scarletOPβ’11mo ago
but that resolving the type to undefined.

afraid-scarletOPβ’11mo ago
and here without using try catch. I also updated the code.

afraid-scarletOPβ’11mo ago
is there any fix? Or Is there any opened issue? Or it won't fix? I don't like the error. Everything is working if it somehow doesn't log the error.
xenial-blackβ’11mo ago
can you please create a github issue for this to track it properly?
afraid-scarletOPβ’11mo ago
I created an issue https://github.com/TanStack/router/issues/3252 If I need to add more information let me know, I will do that.
exotic-emeraldβ’8mo ago
I've run into the same probelem, any ideas?
exotic-emeraldβ’8mo ago
https://stackblitz.com/edit/tanstack-router-rsx7w91m?file=src%2Froutes%2Fposts.route.tsx
here is my reproduction of the issue, ive included a console log of where I want to show the toast and have the rest of the ui show wihout any data of course
Matthew Bevis
StackBlitz
Router Basic React Query File Based Example (forked) - StackBlitz
Run official live example code for Router Basic React Query File Based, created by Tanstack on StackBlitz
exotic-emeraldβ’8mo ago
i've also updated the issue with the same info