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

providetanstackquery.md

106 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```ts
53import {
54 provideTanStackQuery,
55 withDevtools
56 QueryClient,
57} from '@tanstack/angular-query-experimental'
58​
59bootstrapApplication(AppComponent,
60 {
61 providers: [
62 provideTanStackQuery(new QueryClient(), withDevtools())
63 ]
64 }
66```
67​
68**Example: using an InjectionToken**
69​
70```ts
71export const MY_QUERY_CLIENT = new InjectionToken('', {
72 factory: () => new QueryClient(),
73})
74​
75// In a lazy loaded route or lazy loaded component's providers array:
76providers: [provideTanStackQuery(MY_QUERY_CLIENT)]
77```
78Using an InjectionToken for the QueryClient is an advanced optimization which allows TanStack Query to be absent from the main application bundle.
79This can be beneficial if you want to include TanStack Query on lazy loaded routes only while still sharing a `QueryClient`.
80​
81Note that this is a small optimization and for most applications it's preferable to provide the `QueryClient` in the main application config.
82​
83## Parameters
84​
85### queryClient
86​
87A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.
88​
89`QueryClient` | `InjectionToken`\<`QueryClient`\>
90​
91### features
92​
93...[`QueryFeatures`](../../type-aliases/queryfeatures.md)[]
94​
95Optional features to configure additional Query functionality.
96​
97## Returns
98​
99`Provider`[]
100​
101A set of providers to set up TanStack Query.
102​
103## See
104​
105 - https://tanstack.com/query/v5/docs/framework/angular/quick-start
106 - withDevtools