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

provideTanStackQuery.md

91 lines2.6 KB

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