What problem does it solve?
TanStack Query simplifies fetching, caching, synchronizing, and updating remote server state in frontend applications so developers can avoid manual cache management and reduce UI data staleness.
Core Features & Use Cases
- Automatic Caching & Invalidation: Efficiently cache server responses and invalidate by hierarchical keys for precise refetching.
- Background Refetching & Retry Policies: Keep data fresh with configurable refetch intervals, reconnect/focus behaviors, and retry strategies.
- Pagination, Infinite Loading & Optimistic Updates: Built-in patterns for paginated lists, cursor-based infinite queries, and optimistic UI updates with rollback support.
- Use Case: Use it in a React app to prefetch todos in route loaders, show placeholder data during pagination, perform optimistic add/remove operations, and hydrate server-rendered state on the client.
Quick Start
Wrap your app with a QueryClientProvider, create a QueryClient with sensible defaults, and replace direct fetch calls with useQuery or useMutation hooks as appropriate.