Skip to main content
The QueryClientProvider component provides a QueryClient instance to all components in the React component tree. This is required for any TanStack Query hooks to work.

Import

Signature

Props

QueryClient
required
The QueryClient instance to provide to the component tree.
React.ReactNode
The React components that will have access to the QueryClient.

Examples

Basic Usage

With Custom Configuration

With React Query Devtools

Multiple QueryClients

With Error Handling

With Persister

Using State Management

With Next.js App Router

With TypeScript Configuration

Behavior

The QueryClientProvider component:
  1. Provides the QueryClient instance through React context
  2. Automatically calls client.mount() when the component mounts
  3. Automatically calls client.unmount() when the component unmounts
  4. Makes the QueryClient accessible to all child components via useQueryClient

Notes

The QueryClientProvider must be placed above any components that use TanStack Query hooks.
Create the QueryClient instance outside of your component or use useState to ensure a stable instance across renders.
You can nest multiple QueryClientProvider components to use different QueryClient instances in different parts of your app.
The QueryClient should be created once per application. Creating it inside a component without useState will cause performance issues.