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

provideTanStackQuery.md

93 lines2.6 KB

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