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

providetanstackquery.md

103 lines2.1 KB

1---
2id: provideTanStackQuery
3title: provideTanStackQuery
4---
5​
6# Function: provideTanStackQuery()
7​
8```ts
9function provideTanStackQuery(queryClient, ...features): Provider[]
10```
11​
12Sets up providers necessary to enable TanStack Query functionality for Angular applications.
13​
14Allows to configure 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​
49```ts
50import {
51 provideTanStackQuery,
52 withDevtools
53 QueryClient,
54} from '@tanstack/angular-query-experimental'
55​
56bootstrapApplication(AppComponent,
57 {
58 providers: [
59 provideTanStackQuery(new QueryClient(), withDevtools())
60 ]
61 }
63```
64​
65**Example: using an InjectionToken**
66​
67```ts
68export const MY_QUERY_CLIENT = new InjectionToken('', {
69 factory: () => new QueryClient(),
70})
71​
72// In a lazy loaded route or lazy loaded component's providers array:
73providers: [provideTanStackQuery(MY_QUERY_CLIENT)]
74```
75​
76## Parameters
77​
78### queryClient
79​
80A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.
81​
82`QueryClient` | `InjectionToken`\<`QueryClient`\>
83​
84### features
85​
86...[`QueryFeatures`](../../type-aliases/queryfeatures.md)[]
87​
88Optional features to configure additional Query functionality.
89​
90## Returns
91​
92`Provider`[]
93​
94A set of providers to set up TanStack Query.
95​
96## See
97​
98- https://tanstack.com/query/v5/docs/framework/angular/quick-start
99- withDevtools
100​
101## Defined in
102​
103[providers.ts:118](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L118)