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

provideQueryClient.md

42 lines1.3 KB

1---
2id: provideQueryClient
3title: provideQueryClient
4---
5​
6```ts
7function provideQueryClient(queryClient:
8 | QueryClient
9 | InjectionToken<QueryClient>): Provider;
10```
11​
12Defined in: [packages/angular-query-experimental/src/providers.ts:21](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L21)
13​
14Usually [provideTanStackQuery](provideTanStackQuery.md) is used once to set up TanStack Query and the
15[`QueryClient`](https://tanstack.com/query/latest/docs/reference/QueryClient) for the entire application β€”
16it calls `provideQueryClient` internally. Use `provideQueryClient` directly to provide a different
17`QueryClient` instance for part of the application, or for unit testing.
18​
19## Parameters
20​
21### queryClient
22​
23 \| [`QueryClient`](../classes/QueryClient.md)
24 \| `InjectionToken`\<[`QueryClient`](../classes/QueryClient.md)\>
25​
26A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.
27​
28## Returns
29​
30`Provider`
31​
32A provider object that can be used to provide the `QueryClient` instance.
33​
34## Example
35​
36Providing a test-only `QueryClient` in a component test, without wiring up `provideTanStackQuery`'s other
37defaults:
38```ts
39TestBed.configureTestingModule({
40 providers: [provideQueryClient(new QueryClient())],
41})
42```