What problem does it solve?
TanStack Query removes the complexity of fetching, caching, synchronizing, and updating remote server data in client applications, reducing boilerplate and preventing stale or inconsistent UI state.
Core Features & Use Cases
- Automatic Caching & Invalidation: Efficiently cache server responses and invalidate or refetch data by key or predicate.
- Background Refetching & Stale-While-Revalidate: Keep UI data fresh with configurable refetch strategies and intervals.
- Pagination & Infinite Loading: Built-in support for paginated and cursor/infinite queries with helpers for prefetching pages.
- Optimistic Updates & Mutations: Perform optimistic UI updates with rollback support and lifecycle callbacks.
- SSR & Hydration: Prefetch and dehydrate query state on the server for seamless hydration in client render.
- Use Case: Ideal for React/TS applications that need robust data fetching with caching, optimistic UX, pagination, and server-rendered hydration.
Quick Start
Initialize a QueryClient, wrap your app with QueryClientProvider, and use useQuery or useMutation hooks to fetch and mutate server data.