What problem does it solve?
TanStack Query usage patterns address the challenge of keeping server state in sync across client and server components, reducing boilerplate and avoiding stale data by standardizing fetch, cache, and mutation workflows.
Core Features & Use Cases
- Query Factory Pattern: Define reusable queryOptions factories for consistent keys and configurations across client and server.
- Client & Server Integration: Use useQuery and useMutation in client components and prefetch in server components to hydrate on the client.
- Server Prefetching & Hydration: Prefetch data on the server and hydrate on the client with consistent caching keys.
- Cache Invalidation & Optimistic Updates: Invalidate queries after mutations and apply optimistic updates for instant UI feedback.
- Dependent Queries & Error Handling: Coordinate queries based on data availability and configure retries and staleTime.
Quick Start
Create a queryOptions factory for your data requests and hook it up with useQuery in a client component to fetch data.