Preventing a specific query from triggering `onError`
I have the following client setup
And in my RootRoute, I fetch user data on
beforeLoad
function and immediately showing the pendingCompoent
. When the query fails, it triggers the toast.error
and then redirects.
Is there a way to prevent this specific query used in beforeLoad
to trigger the toast message?4 Replies
frail-apricot•13mo ago
this is a question better suited in #react-query-questions
however, since I know the answer I will add it here 🙂
frail-apricot•13mo ago
you should have a look at @TkDodo 🔮 's excellent blog: https://tkdodo.eu/blog/breaking-react-querys-api-on-purpose#defining-on-demand-messages
Breaking React Query's API on purpose
Why good API design matters, even if it means breaking existing APIs in the face of resistance.
frail-apricot•13mo ago
in your case, I would use the query meta functionality to tag a query as "do not show the error" as follows:
1. register a type for the queryMeta property
2. only show the toast if
swallowError
is falsy:
3. in your loader, set swallowError
to true:
genetic-orangeOP•13mo ago
Oh, sorry I just mixed up the channels as both of them are on my side bar.
Thanks for the thorough example and solution!