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

providetanstackquery.md

108 lines2.6 KB

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