What is React Query?
React Query is a JavaScript library that helps you work with server data in React applications. You can think of it as an async state manager.
React is brilliant at helping you manage your client-side state but it doesn’t offer much guidance on how to manage server-side state / data. For example, it doesn’t answer important questions like:
- How to query remote data
- How to mutate remote data
- How to cache remote data
- How to deal with network errors
- How to implement parallel queries
- How to perform optimistic updates
This means that developers typically cobble together their own approach or replicate what they’ve read from a bunch of blog posts.
React Query can be thought of as the missing data-fetching library for React. A battle-tested library that offers a standardized approach to working with server data so that you can waste less time trying to solve problems that have already been solved.
Here are some of the features that React Query provides:
- Queries: for fetching server data
- Mutations: for updating server data
- Caching
- Parallel queries
- Offline support
- Query retries
- Scroll position restoration
- Infinite queries
- Paginated queries
- Query cancellation
- Prefetching
- Polling
- Error handling
- Placeholder query data
- Optimistic updates
Implementing those features yourself would take a lot of time and introduce a lot of complexity to your code.
Sources
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment