Setting an ErroHandler for all queries #2139
-
Hello, I have a use case where i want to catch an Error in every single query,. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
you can use the
this is documented here: https://react-query.tanstack.com/reference/QueryCache |
Beta Was this translation helpful? Give feedback.
-
Quick follow up on this... |
Beta Was this translation helpful? Give feedback.
-
so I think you can just export the history from react-router that your are passing tp your that being said, if you need to use hooks in those callbacks, you can create the QueryClientProvider inside of your App component, but make sure you stabilize it correctly (NOT useMemo, useState or useRef). I have a blog post about this here: https://tkdodo.eu/blog/use-state-for-one-time-initializations and I use it like this to e.g. show an error toast for all errors globally:
|
Beta Was this translation helpful? Give feedback.
-
You are amazing.
Thanks for all your help in this.
CUBE Workspace
Corporate: 6240 Som Center Rd #130
Solon, OH 44139
T: 216.245.9629
…On Mon, Apr 19, 2021 at 12:57 AM Dominik Dorfmeister < ***@***.***> wrote:
Yes, on this example, you’d need a ToastProvider around the App component.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2139 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMKORZXOXQSML7O6SHL6OE3TJOZ33ANCNFSM43BZCVLA>
.
|
Beta Was this translation helpful? Give feedback.
you can use the
onError
property globally in thedefaultOptions
of thequeryClient
, but if you override this on a query, it will not be called. For an error handler that is always called, not matter what, you have to put it on the queryCache:this is documented here: https://react-query.tanstack.com/reference/QueryCache