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

provideTanStackQuery.md

102 lines2.5 KB

1---
2id: provideTanStackQuery
3title: provideTanStackQuery
4---
5​
6```ts
7function provideTanStackQuery(queryClient, ...features): Provider[];
8```
9​
10Defined in: [providers.ts:105](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L105)
11​
12Sets up providers necessary to enable TanStack Query functionality for Angular applications.
13​
14Allows configuring a `QueryClient` and optional features such as developer tools.
15​
16**Example - standalone**
17​
18```ts
19import {
20 provideTanStackQuery,
21 QueryClient,
22} from '@tanstack/angular-query-experimental'
23​
24bootstrapApplication(AppComponent, {
25 providers: [provideTanStackQuery(new QueryClient())],
26})
27```
28​
29**Example - NgModule-based**
30​
31```ts
32import {
33 provideTanStackQuery,
34 QueryClient,
35} from '@tanstack/angular-query-experimental'
36​
37@NgModule({
38 declarations: [AppComponent],
39 imports: [BrowserModule],
40 providers: [provideTanStackQuery(new QueryClient())],
41 bootstrap: [AppComponent],
42})
43export class AppModule {}
44```
45​
46You can also enable optional developer tools by adding `withDevtools`. By
47default the tools will then be loaded when your app is in development mode.
48```ts
49import {
50 provideTanStackQuery,
51 withDevtools
52 QueryClient,
53} from '@tanstack/angular-query-experimental'
54​
55bootstrapApplication(AppComponent,
56 {
57 providers: [
58 provideTanStackQuery(new QueryClient(), withDevtools())
59 ]
60 }
62```
63​
64**Example: using an InjectionToken**
65​
66```ts
67export const MY_QUERY_CLIENT = new InjectionToken('', {
68 factory: () => new QueryClient(),
69})
70​
71// In a lazy loaded route or lazy loaded component's providers array:
72providers: [provideTanStackQuery(MY_QUERY_CLIENT)]
73```
74Using an InjectionToken for the QueryClient is an advanced optimization which allows TanStack Query to be absent from the main application bundle.
75This can be beneficial if you want to include TanStack Query on lazy loaded routes only while still sharing a `QueryClient`.
76​
77Note that this is a small optimization and for most applications it's preferable to provide the `QueryClient` in the main application config.
78​
79## Parameters
80​
81### queryClient
82​
83A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.
84​
85`QueryClient` | `InjectionToken`\<`QueryClient`\>
86​
87### features
88​
89...[`QueryFeatures`](../type-aliases/QueryFeatures.md)[]
90​
91Optional features to configure additional Query functionality.
92​
93## Returns
94​
95`Provider`[]
96​
97A set of providers to set up TanStack Query.
98​
99## See
100​
101 - https://tanstack.com/query/v5/docs/framework/angular/quick-start
102 - withDevtools