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

providers.ts

26 lines714 Bytes

1import {
2 DestroyRef,
3 ENVIRONMENT_INITIALIZER,
4 inject,
5 makeEnvironmentProviders,
6} from '@angular/core'
7import { provideQueryClient } from './inject-query-client'
8import type { EnvironmentProviders } from '@angular/core'
9import type { QueryClient } from '@tanstack/query-core'
10​
11export function provideAngularQuery(
12 queryClient: QueryClient,
13): EnvironmentProviders {
14 return makeEnvironmentProviders([
15 provideQueryClient(queryClient),
16 {
17 provide: ENVIRONMENT_INITIALIZER,
18 multi: true,
19 useValue: () => {
20 queryClient.mount()
21 // Unmount the query client on application destroy
22 inject(DestroyRef).onDestroy(() => queryClient.unmount())
23 },
24 },
25 ])