Installation
Learn how to install and set up TanStack Query in your React application.Requirements
TanStack Query is compatible with React v18 and v19.- React 18.0.0 or later
- React 19.0.0 or later
React Query version 5.90.21 and above supports both React 18 and React 19. Make sure you’re using a compatible version.
Package Installation
1
Install the package
Install TanStack Query using your preferred package manager:
2
Install DevTools (Optional)
For development, install the DevTools package:
Setup
1
Create a QueryClient
Create a You can configure default options for all queries and mutations:
QueryClient instance to manage queries and mutations:2
Wrap your app with QueryClientProvider
Provide the
QueryClient to your React app using the QueryClientProvider:3
Add DevTools (Development)
Import and add the DevTools component for development:
The DevTools component only renders in development mode (
NODE_ENV === 'development'), so you don’t need to conditionally import it.Complete Example
Here’s a complete setup example:src/main.tsx
Configuration Options
Customize theQueryClient with these common options:
Query Options
Mutation Options
Environment-Specific Configuration
Configure different settings for development and production:Next.js Setup
For Next.js applications, create a separate client component:app/providers.tsx
app/layout.tsx
Persister Setup (Optional)
To persist query cache across sessions:Verification
Verify your installation by creating a simple query:src/App.tsx
If you see the DevTools floating button in the bottom-right corner of your app, React Query is successfully installed!
Next Steps
Quick Start
Build your first React Query application
TypeScript
Configure TypeScript for type-safe queries