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

inject-query-client.ts

24 lines782 Bytes

1import { Injector, inject } from '@angular/core'
2import { QueryClient } from '@tanstack/query-core'
3import type { InjectOptions } from '@angular/core'
4​
5/**
6 * Injects a `QueryClient` instance and allows passing a custom injector.
7 *
8 * @deprecated Use `inject(QueryClient)` instead.
9 * If you need to get a `QueryClient` from a custom injector, use `injector.get(QueryClient)`.
10 *
11 *
12 * **Example**
13 * ```ts
14 * const queryClient = injectQueryClient();
15 * ```
16 * @param injectOptions - Type of the options argument to inject and optionally
17 * a custom injector.
18 * @returns The `QueryClient` instance.
19 */
20export function injectQueryClient(
21 injectOptions: InjectOptions & { injector?: Injector } = {},
22) {
23 return (injectOptions.injector ?? inject(Injector)).get(QueryClient)