React Query?? Fetching data with React is generally a process that involves a lot of code. You often need to use the “useEffect” hook in combination with “useState” to manage the fetched data. This requires a lot of boilerplate that we have to write in every component in which we want to fetch data. Become a Medium member React Query can help you cut down on the code you write when making network requests with React. All of this React code that we had to write before can be replaced with the hook “useQuery”. From it we get back all of the data that we need without having to declare a state variable: However, making data fetching easier only covers a small slice of what React Query does. What makes it a very powerful library is that it caches (saves) requests that we make. So in many cases if we’ve requested data before, we don’t have to make another request, we can just read it from the cache. This is immensely helpful because it cuts down repetition in our code, reduces the load we put on our API, and helps us manage our overall app state. If you pick any library to start adding to your projects today out of this list, make it React Query. #reactjs #javascript #useEffect #useQuery #nextjs
True, but I feel like the main benefit of using react query is that it gives you a global caching mechanism for requests. If you're just using it to reduce the amount of boilerplate you need to write for managing loading states you wind up with a number of stray query keys throughout your app and unnecessarily having to manage a context provider for the data fetching client.
react-query is outdated, use @tanstack/react-query instead
react-query is outdated, use @tanstack/react-query instead
Congratulations and best of luck in your next steps.