Can Anyone Help? Best Approach for onError and onSuccess in Custom useQuery with React Query v5 #8242
-
Hello React Query team! At my workplace, I recently proposed and implemented the use of React Query, which my team and I are really enjoying so far. We had an idea to create a custom useQuery hook that wraps the default useQuery, applying only a few specific options by default. I believe this approach shouldn't cause issues, correct? However, my main question is about something my team suggested—adding onError and onSuccess callbacks within this custom useQuery. After researching, I noticed that these callbacks were removed in version 5 for specific reasons. This made me question if it’s problematic to implement them like this. In my opinion, having an onSuccess callback seems unnecessary, and onError shouldn’t be mandatory. I’d love to understand the reasoning behind removing these callbacks and whether it's considered a "wrong" way to use the library if we add them back. Thank you so much for your time! I always read through community discussions, and now I'm trying to engage more, even though English isn’t my first language. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
What are you planning to do in those callbacks? Note that they would run for every instance that uses them, so doing something like logging / displaying error toast will just lead to multiples being displayed ... I have outlined the problems here: https://tkdodo.eu/blog/breaking-react-querys-api-on-purpose |
Beta Was this translation helpful? Give feedback.
What are you planning to do in those callbacks? Note that they would run for every instance that uses them, so doing something like logging / displaying error toast will just lead to multiples being displayed ...
I have outlined the problems here: https://tkdodo.eu/blog/breaking-react-querys-api-on-purpose