TanStack Query (React Query)
For detailed React Query integration, see the React Query Integration guide.Quick Setup
lib/api-client.ts
Other Framework Variants
The same patterns work across all TanStack Query variants:Vue Query
composables/useTodos.ts
Svelte Query
lib/queries.ts
Solid Query
components/TodoList.tsx
TanStack Router
TanStack Router’s loaders work perfectly with CallApi:Route Loaders
routes/todos.tsx
Dynamic Routes with Params
routes/todos.$id.tsx
Combining Router with Query
For the best experience, combine TanStack Router with TanStack Query:routes/todos.tsx
Error Handling in Loaders
routes/users.$id.tsx
TanStack Table
CallApi works seamlessly with TanStack Table for server-side pagination, sorting, and filtering:Basic Server-Side Table
components/UsersTable.tsx
Advanced: Sorting and Filtering
components/AdvancedTable.tsx
Best Practices
1. Centralized API Configuration
Create separate clients for different purposes:lib/api-clients.ts
2. Shared Query Options
Define reusable query options:lib/query-options.ts
3. Type-Safe API Layer
Create a typed API layer:api/index.ts
4. Error Boundaries
Use error boundaries with TanStack Router:routes/__root.tsx
Summary
CallApi provides consistent patterns across the entire TanStack ecosystem:- TanStack Query: Configure with
throwOnError: trueandresultMode: "onlyData" - TanStack Router: Use in loaders with full TypeScript support
- TanStack Table: Perfect for server-side pagination, sorting, and filtering
- All Frameworks: Same patterns work in React, Vue, Svelte, and Solid
- Type-safe API calls
- Automatic retries and error handling
- Request deduplication
- Schema validation
- Excellent developer experience