Skip to content
Discussion options

You must be logged in to vote

What you probably want to do is use the onError callback on the queryCache rather than the defaultOptions for queries. This has two reasons:

  1. default options only work if they are not overwritten. If your useQuery hook specifies their own onError, to e.g. show a toast error notification, you won't track the error. There is no chaining here.
  2. This onError callback will be called for each observer, so if you have two queries with the same key, it will be called twice and thus tracked twice.

The callback on the queryCache solves this. It will only be called once per cache entry, and it also receives the whole query as second parameter, which also has the key:

see: https://react-query.tanstac…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@mauriciosoares
Comment options

@TkDodo
Comment options

@mauriciosoares
Comment options

Answer selected by mauriciosoares
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants