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

provideQueryClient.md

41 lines1.2 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:22](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L22)
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​
23A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.
24​
25[`QueryClient`](../classes/QueryClient.md) | `InjectionToken`\<[`QueryClient`](../classes/QueryClient.md)\>
26​
27## Returns
28​
29`Provider`
30​
31A provider object that can be used to provide the `QueryClient` instance.
32​
33## Example
34​
35Providing a test-only `QueryClient` in a component test, without wiring up `provideTanStackQuery`'s other
36defaults:
37```ts
38TestBed.configureTestingModule({
39 providers: [provideQueryClient(new QueryClient())],
40})
41```