![]() ![]() This is certainly okay for some scenarios, but has a couple of drawbacks, too: Here, we're handling error situations by checking for the isError boolean flag (which is derived from the status enum) given to us by React Query. Let's see how most examples around displaying errors look like: If you are working with the fetch API or other libraries that do not give you a rejected Promise on erroneous status codes like 4xx or 5xx, you'll have to do the transformation yourself in the queryFn. Luckily, this is exactly what you'll get when you work with libraries like axios. React Query needs a rejected Promise in order to handle errors correctly. To avoid that, let's dive into what options React Query offers us when it comes to error handling. However, not thinking about how we are going to handle our errors might negatively affect user experience. We like to handle "sunshine cases" first where error handling becomes an afterthought. Oftentimes, it is something that we don't focus on right from the beginning though. We have to face it: Not all requests will be successful, and not all Promises will be fulfilled. Handling errors is an integral part of working with asynchronous data, especially data fetching. #12: Mastering Mutations in React Query. ![]() #9: Placeholder and Initial Data in React Query.#8a: Leveraging the Query Function Context. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |