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

provideTanStackQuery.md

104 lines2.5 KB

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