TanStack Query Integration
Modular guides for integrating TanStack Query with oRPC for type-safe, performant data fetching and state management.
Core Concepts
The web app uses tanstackRPC (from @~/utils/tanstack-orpc.ts) which applies createTanstackQueryUtils to the oRPC client. Every contract procedure gets:
- •
.queryOptions()- Query configuration - •
.mutationOptions()- Mutation configuration - •
.queryKey()- Type-safe query key generation - •
.call()- Direct procedure call
Quick Reference
| Guide | Use When |
|---|---|
| Query Hooks | Creating hooks for data fetching, exporting query options |
| Mutation Hooks | Implementing mutations with cache invalidation |
| Optimistic Updates | Making UI instant with optimistic cache updates |
| Cache Invalidation | Keeping data fresh after mutations |
| Route Integration | Prefetching data in route loaders |
| Loading States | Handling loading, error, and empty states |
| Best Practices | 10 critical best practices to follow |
Learning Path
Beginner: Start with Query Hooks → Mutation Hooks → Loading States
Intermediate: Add Optimistic Updates → Cache Invalidation
Advanced: Route Integration → Best Practices
See Also
- •examples/complete-hooks.ts - Full working examples