Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

QueryClientProvider.md

54 lines1.7 KB

1---
2id: QueryClientProvider
3title: QueryClientProvider
4redirect_from:
5 - framework/react/reference/QueryClientProvider
6---
7​
8<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
9​
10```ts
11function QueryClientProvider(props: QueryClientProviderProps): Element;
12```
13​
14Defined in: [packages/react-query/src/QueryClientProvider.tsx:69](https://github.com/TanStack/query/blob/main/packages/react-query/src/QueryClientProvider.tsx#L69)
15​
16Use the `QueryClientProvider` component to connect and provide a `QueryClient` to your application. Also
17calls `client.mount()`/`client.unmount()` as this component mounts/unmounts, which subscribes the client to
18focus/online events (resuming any paused mutations and refetching as needed when the app regains focus or
19comes back online).
20​
21## Parameters
22​
23### props
24​
25[`QueryClientProviderProps`](../type-aliases/QueryClientProviderProps.md)
26​
27The `client` to provide, and the `children` that get access to it.
28​
29<a id="props-properties"></a>
30​
31#### `props` properties
32​
33| Property | Type | Description |
34| ------ | ------ | ------ |
35| <a id="props-property-children"></a> `children?` | `React.ReactNode` | The components that get access to the provided `QueryClient`. |
36| <a id="props-property-client"></a> `client` | [`QueryClient`](../classes/QueryClient.md) | **Required** The `QueryClient` instance to provide. |
37​
38## Returns
39​
40`Element`
41​
42The provided `children`, wrapped so they can read the `QueryClient` via `useQueryClient`.
43​
44## Example
45​
46```tsx
47import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
48​
49const queryClient = new QueryClient()
50​
51function App() {
52 return <QueryClientProvider client={queryClient}>...</QueryClientProvider>
54```