How to efficiently handle erros if there are multiple useQuery calls on the same page/component?
When I have multiple useQuery calls on the page(lfor example when there are api calls for dropdowns as well as main list), I want to alert user if any of the api call fails via a toaster alert with a dedicated message. What is a better way to handle errors in this case, if using onError callback is soon going to be deprecated. Do i write multiple useEffects?
Also I cannot tear down ui by putting checks on error state for each of the drop down api error case
1 Reply
helpful-purple•3y ago
You can use a global onError callback: https://tkdodo.eu/blog/react-query-error-handling#the-global-callbacks
React Query Error Handling
After covering the sunshine cases of data fetching, it's time to look at situations where things don't go as planned and "Something went wrong..."