Open History to see the last commit
1---
2id: injectQuery
3title: injectQuery
4---
5β
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7β
8## Overview
9β
10```ts
11function injectQuery<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends readonly unknown[] = readonly unknown[]>(injectQueryFn: () => DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, options?: InjectQueryOptions): DefinedCreateQueryResult<TData, TError>;
12function injectQuery<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends readonly unknown[] = readonly unknown[]>(injectQueryFn: () => UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, options?: InjectQueryOptions): CreateQueryResult<TData, TError>;
13function injectQuery<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends readonly unknown[] = readonly unknown[]>(injectQueryFn: () => CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, options?: InjectQueryOptions): CreateQueryResult<TData, TError>;
14```
15β
16- [`() => DefinedInitialDataOptions` β `DefinedCreateQueryResult`](#call-signature-1): This overload is selected when `initialData` is known to be defined on the options returned by `injectQueryFn`, so the resulting `data` signal is never `undefined` (unless a `select` changes `TData` to include `undefined`).
17- [`() => UndefinedInitialDataOptions` β `CreateQueryResult`](#call-signature-2): Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
18- [`() => CreateQueryOptions` β `CreateQueryResult`](#call-signature-3): This overload accepts the general [CreateQueryOptions](../interfaces/CreateQueryOptions.md) shape rather than the `initialData`-aware overloads above, so whether `data` is defined can't be inferred from the call site β useful when wrapping `injectQuery` in your own helper function that forwards caller-provided options.
19β
20See also: [Parameters](#parameters-summary) Β· [Returns](#returns-summary)
21β
22<a id="call-signature-1"></a>
23β
24## Call Signature
25β
26```ts
27function injectQuery<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends readonly unknown[] = readonly unknown[]>(injectQueryFn: () => DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, options?: InjectQueryOptions): DefinedCreateQueryResult<TData, TError>;
28```
29β
30Defined in: [packages/angular-query-experimental/src/inject-query.ts:72](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-query.ts#L72)
31β
32This overload is selected when `initialData` is known to be defined on the options returned by
33`injectQueryFn`, so the resulting `data` signal is never `undefined` (unless a `select` changes `TData` to
34include `undefined`).
35β
36### Type Parameters
37β
38#### TQueryFnData
39β
40`TQueryFnData` = `unknown`
41β
42#### TError
43β
44`TError` = `Error`
45β
46#### TData
47β
48`TData` = `TQueryFnData`
49β
50#### TQueryKey
51β
52`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
53β
54### Parameters
55β
56#### injectQueryFn
57β
58() => [`DefinedInitialDataOptions`](../type-aliases/DefinedInitialDataOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>
59β
60A function returning the [DefinedInitialDataOptions](../type-aliases/DefinedInitialDataOptions.md) to use β everything you
61can pass to `injectQuery`, with `initialData` known to be defined. Similar to `computed` from Angular, this
62function runs in the reactive context, so signals read inside it (in `queryKey`, `enabled`, etc.) drive the
63query.
64β
65#### options?
66β
67[`InjectQueryOptions`](../interfaces/InjectQueryOptions.md)
68β
69Additional configuration
70β
71### Returns
72β
73[`DefinedCreateQueryResult`](../type-aliases/DefinedCreateQueryResult.md)\<`TData`, `TError`\>
74β
75The query result, typed so that `data` is never `undefined` (unless a `select` changes `TData` to
76include `undefined`). At runtime, `data` is still `undefined` if `select` throws on its first call.
77β
78### See
79β
80 - https://tanstack.com/query/latest/docs/framework/angular/guides/queries
81 - [queryOptions](queryOptions.md) to share these options between `injectQuery` and imperative APIs like
82`queryClient.fetchQuery`.
83β
84### Example
85β
86```angular-ts
87@Component({
88 selector: 'posts',
89 template: `
90 <!-- `postsQuery.data()` is `Post[]`, never `undefined`, thanks to `initialData` β even if a
91 refetch fails, so the list stays visible alongside the error. -->
92 @if (postsQuery.isError()) {
93 <span>Error: {{ postsQuery.error()?.message }}</span>
94 }
95 <ul>
96 @for (post of postsQuery.data(); track post.id) {
97 <li>{{ post.title }}</li>
98 }
99 </ul>
100 `,
101})
102export class Posts {
103 readonly postsQuery = injectQuery(() => ({
104 queryKey: ['posts'],
105 queryFn: fetchPosts,
106 initialData: [],
107 }))
108}
109```
110β
111<a id="call-signature-2"></a>
112β
113## Call Signature
114β
115```ts
116function injectQuery<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends readonly unknown[] = readonly unknown[]>(injectQueryFn: () => UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, options?: InjectQueryOptions): CreateQueryResult<TData, TError>;
117```
118β
119Defined in: [packages/angular-query-experimental/src/inject-query.ts:159](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-query.ts#L159)
120β
121Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
122β
123### Type Parameters
124β
125#### TQueryFnData
126β
127`TQueryFnData` = `unknown`
128β
129#### TError
130β
131`TError` = `Error`
132β
133#### TData
134β
135`TData` = `TQueryFnData`
136β
137#### TQueryKey
138β
139`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
140β
141### Parameters
142β
143#### injectQueryFn
144β
145() => [`UndefinedInitialDataOptions`](../type-aliases/UndefinedInitialDataOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>
146β
147A function returning the [UndefinedInitialDataOptions](../type-aliases/UndefinedInitialDataOptions.md) to use β everything
148you can pass to `injectQuery`. Similar to `computed` from Angular, this function runs in the reactive
149context, so signals read inside it (in `queryKey`, `enabled`, etc.) drive the query.
150β
151#### options?
152β
153[`InjectQueryOptions`](../interfaces/InjectQueryOptions.md)
154β
155Additional configuration
156β
157### Returns
158β
159[`CreateQueryResult`](../type-aliases/CreateQueryResult.md)\<`TData`, `TError`\>
160β
161The query result. `status()` is `'error'` if the query has an error from a fetch that failed
162after its retries or if `select` threw, `'success'` if the query has data to display (including
163`placeholderData`), and `'pending'` otherwise. `isPending`/`isSuccess`/`isError` are type-guard methods
164for convenience.
165β
166### See
167β
168 - https://tanstack.com/query/latest/docs/framework/angular/guides/queries
169 - [queryOptions](queryOptions.md) to share these options between `injectQuery` and imperative APIs like
170`queryClient.fetchQuery`.
171β
172### Examples
173β
174```angular-ts
175@Component({
176 selector: 'posts',
177 template: `
178 @if (postsQuery.isPending()) {
179 Loading...
180 } @else if (postsQuery.isError()) {
181 <span>Error: {{ postsQuery.error()?.message }}</span>
182 } @else {
183 <ul>
184 @for (post of postsQuery.data(); track post.id) {
185 <li>{{ post.title }}</li>
186 }
187 </ul>
188 }
189 `,
190})
191export class Posts {
192 readonly postsQuery = injectQuery(() => ({
193 queryKey: ['posts'],
194 queryFn: fetchPosts,
195 }))
196}
197```
198β
199Similar to `computed` from Angular, the function passed to `injectQuery` runs in the reactive context. In
200the example below, the query is automatically enabled and executed when the filter signal changes to a
201truthy value. When the filter signal changes back to a falsy value, the query is disabled.
202```angular-ts
203@Component({
204 selector: 'posts',
205 template: `
206 <input [ngModel]="filter()" (ngModelChange)="filter.set($event)" />
207 @if (postsQuery.isPending()) {
208 Loading...
209 } @else if (postsQuery.isError()) {
210 <span>Error: {{ postsQuery.error()?.message }}</span>
211 } @else {
212 <ul>
213 @for (post of postsQuery.data(); track post.id) {
214 <li>{{ post.title }}</li>
215 }
216 </ul>
217 }
218 `,
219})
220export class Posts {
221 readonly filter = signal('')
222β
223 readonly postsQuery = injectQuery(() => ({
224 queryKey: ['posts', this.filter()],
225 queryFn: () => fetchPosts(this.filter()),
226 // Signals can be combined with expressions
227 enabled: !!this.filter(),
228 }))
229}
230```
231β
232<a id="call-signature-3"></a>
233β
234## Call Signature
235β
236```ts
237function injectQuery<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends readonly unknown[] = readonly unknown[]>(injectQueryFn: () => CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, options?: InjectQueryOptions): CreateQueryResult<TData, TError>;
238```
239β
240Defined in: [packages/angular-query-experimental/src/inject-query.ts:185](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-query.ts#L185)
241β
242This overload accepts the general [CreateQueryOptions](../interfaces/CreateQueryOptions.md) shape rather than the `initialData`-aware
243overloads above, so whether `data` is defined can't be inferred from the call site β useful when wrapping
244`injectQuery` in your own helper function that forwards caller-provided options.
245β
246### Type Parameters
247β
248#### TQueryFnData
249β
250`TQueryFnData` = `unknown`
251β
252#### TError
253β
254`TError` = `Error`
255β
256#### TData
257β
258`TData` = `TQueryFnData`
259β
260#### TQueryKey
261β
262`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
263β
264### Parameters
265β
266#### injectQueryFn
267β
268() => [`CreateQueryOptions`](../interfaces/CreateQueryOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>
269β
270A function that returns query options. Similar to `computed` from Angular, this
271function runs in the reactive context, so signals read inside it (in `queryKey`, `enabled`, etc.) drive
272the query.
273β
274#### options?
275β
276[`InjectQueryOptions`](../interfaces/InjectQueryOptions.md)
277β
278Additional configuration
279β
280### Returns
281β
282[`CreateQueryResult`](../type-aliases/CreateQueryResult.md)\<`TData`, `TError`\>
283β
284The query result.
285β
286### See
287β
288https://tanstack.com/query/latest/docs/framework/angular/guides/queries
289β
290<a id="parameters-summary"></a>
291β
292## Parameters
293β
294### injectQueryFn
295β
296() => [`CreateQueryOptions`](../interfaces/CreateQueryOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>
297β
298A function that returns query options. Similar to `computed` from Angular, this
299function runs in the reactive context, so signals read inside it (in `queryKey`, `enabled`, etc.) drive
300the query.
301β
302<a id="injectQueryFn-properties"></a>
303β
304#### `injectQueryFn` properties
305β
306| Property | Type | Default value | Description |
307| ------ | ------ | ------ | ------ |
308| <a id="injectQueryFn-property-enabled"></a> `enabled?` | \| `false` \| `true` \| ((`query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, `TQueryFnData`, `TQueryKey`\>) => `boolean`) | `true` | Set this to `false` or a function that returns `false` to disable automatic refetching when the query mounts or changes query keys. To refetch the query, use the `refetch` method returned from the `useQuery` instance. Accepts a boolean or function that returns a boolean. |
309| <a id="injectQueryFn-property-gctime"></a> `gcTime?` | `number` | `undefined` | The time in milliseconds that unused/inactive cache data remains in memory. When a query's cache becomes unused or inactive, that cache data will be garbage collected after this duration. When different garbage collection times are specified, the longest one will be used. Setting it to `Infinity` will disable garbage collection. Defaults to `5 * 60 * 1000` (5 minutes), or `Infinity` during SSR. Note: the maximum allowed time is about 24 days, imposed by `setTimeout`'s 32-bit signed integer delay β see `timeoutManager.setTimeoutProvider` for a workaround. |
310| <a id="injectQueryFn-property-initialdata"></a> `initialData?` | `TQueryFnData` \| (() => `TQueryFnData` \| `undefined`) | `undefined` | If set, this value will be used as the initial data for the query cache (as long as the query hasn't been created or cached yet). If set to a function, the function will be called **once** during the shared/root query initialization, and be expected to synchronously return the initial data. Initial data is considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the cache. |
311| <a id="injectQueryFn-property-initialdataupdatedat"></a> `initialDataUpdatedAt?` | `number` \| (() => `number` \| `undefined`) | `undefined` | If set, this value will be used as the time (in milliseconds) of when the `initialData` itself was last updated. |
312| <a id="injectQueryFn-property-maxpages"></a> `maxPages?` | `number` | `undefined` | Maximum number of pages to store in the data of an infinite query. |
313| <a id="injectQueryFn-property-meta"></a> `meta?` | `Record`\<`string`, `unknown`\> | `undefined` | Additional payload to be stored on each query. Use this property to pass information that can be used in other places. |
314| <a id="injectQueryFn-property-networkmode"></a> `networkMode?` | `"online"` \| `"always"` \| `"offlineFirst"` | `'online'` | Controls whether a query is allowed to run based on the current network connectivity. **See** [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information. |
315| <a id="injectQueryFn-property-notifyonchangeprops"></a> `notifyOnChangeProps?` | \| ( \| `"error"` \| `"data"` \| `"isError"` \| `"isPending"` \| `"isLoading"` \| `"isLoadingError"` \| `"isRefetchError"` \| `"isSuccess"` \| `"isPlaceholderData"` \| `"status"` \| `"dataUpdatedAt"` \| `"errorUpdatedAt"` \| `"failureCount"` \| `"failureReason"` \| `"errorUpdateCount"` \| `"isFetched"` \| `"isFetchedAfterMount"` \| `"isFetching"` \| `"isInitialLoading"` \| `"isPaused"` \| `"isRefetching"` \| `"isStale"` \| `"isEnabled"` \| `"refetch"` \| `"fetchStatus"` \| `"fetchNextPage"` \| `"fetchPreviousPage"` \| `"hasNextPage"` \| `"hasPreviousPage"` \| `"isFetchNextPageError"` \| `"isFetchingNextPage"` \| `"isFetchPreviousPageError"` \| `"isFetchingPreviousPage"`)[] \| `"all"` \| (() => \| `"all"` \| ( \| `"error"` \| `"data"` \| `"isError"` \| `"isPending"` \| `"isLoading"` \| `"isLoadingError"` \| `"isRefetchError"` \| `"isSuccess"` \| `"isPlaceholderData"` \| `"status"` \| `"dataUpdatedAt"` \| `"errorUpdatedAt"` \| `"failureCount"` \| `"failureReason"` \| `"errorUpdateCount"` \| `"isFetched"` \| `"isFetchedAfterMount"` \| `"isFetching"` \| `"isInitialLoading"` \| `"isPaused"` \| `"isRefetching"` \| `"isStale"` \| `"isEnabled"` \| `"refetch"` \| `"fetchStatus"` \| `"fetchNextPage"` \| `"fetchPreviousPage"` \| `"hasNextPage"` \| `"hasPreviousPage"` \| `"isFetchNextPageError"` \| `"isFetchingNextPage"` \| `"isFetchPreviousPageError"` \| `"isFetchingPreviousPage"`)[] \| `undefined`) | `undefined` | If set, the component will only re-render if any of the listed properties change. When set to `['data', 'error']`, the component will only re-render when the `data` or `error` properties change. When set to `'all'`, the component will re-render whenever a query is updated. When set to a function, the function will be executed to compute the list of properties. Defaults to `undefined`, in which case property access is tracked automatically, and the component only re-renders when one of the tracked properties changes. |
316| <a id="injectQueryFn-property-persister"></a> `persister?` | (`queryFn`: (`context`: `object`) => `TQueryFnData` \| `Promise`\<`TQueryFnData`\>, `context`: `object`, `query`: [`Query`](../classes/Query.md)) => `TQueryFnData` \| `Promise`\<`TQueryFnData`\> | `undefined` | This option can be used to persist the result of a query to an external storage, bypassing the need to actually call the `queryFn`. Useful for persisting a query's data across e.g. server/client boundaries. |
317| <a id="injectQueryFn-property-placeholderdata"></a> `placeholderData?` | \| `NonFunctionGuard`\<`TQueryFnData`\> \| ((`previousData`: `NonFunctionGuard`\<`TQueryFnData`\> \| `undefined`, `previousQuery`: \| [`Query`](../classes/Query.md)\<`NonFunctionGuard`\<`TQueryFnData`\>, `TError`, `NonFunctionGuard`\<`TQueryFnData`\>, `TQueryKey`\> \| `undefined`) => `NonFunctionGuard`\<`TQueryFnData`\> \| `undefined`) | `undefined` | If set, this value will be used as the placeholder data for this particular query observer while the query is still in the `loading` data and no initialData has been provided. |
318| <a id="injectQueryFn-property-queryfn"></a> `queryFn?` | \| *typeof* [`skipToken`](../variables/skipToken.md) \| ((`context`: `object`) => `TQueryFnData` \| `Promise`\<`TQueryFnData`\>) | `undefined` | The function that the query will use to request data. Required, unless a default query function has been set via `queryClient.setQueryDefaults` or `queryClient.setDefaultOptions`. Receives a [QueryFunctionContext](../type-aliases/QueryFunctionContext.md). Must return a promise that will either resolve data or throw an error. The data cannot be `undefined`. |
319| <a id="injectQueryFn-property-queryhash"></a> `queryHash?` | `string` | `undefined` | The hashed form of `queryKey`, computed with `queryKeyHashFn` (or the default hashing function otherwise). Used as the actual cache key internally. |
320| <a id="injectQueryFn-property-querykey"></a> `queryKey` | `TQueryKey` & `object` | `undefined` | The query key to use for this query. The query key will be hashed into a stable hash. See [Query Keys](https://tanstack.com/query/latest/docs/framework/react/guides/query-keys) for more information. The query will automatically update when this key changes (as long as `enabled` is not set to `false`). |
321| <a id="injectQueryFn-property-querykeyhashfn"></a> `queryKeyHashFn?` | (`queryKey`: `TQueryKey`) => `string` | `undefined` | If specified, this function is used to hash the `queryKey` to a string. |
322| <a id="injectQueryFn-property-refetchinterval"></a> `refetchInterval?` | \| `number` \| `false` \| ((`query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, `TQueryFnData`, `TQueryKey`\>) => `number` \| `false` \| `undefined`) | `false` | If set to a number, the query will continuously refetch at this frequency in milliseconds. If set to a function, the function will be executed with the latest data and query to compute a frequency |
323| <a id="injectQueryFn-property-refetchintervalinbackground"></a> `refetchIntervalInBackground?` | `boolean` | `false` | If set to `true`, the query will continue to refetch while their tab/window is in the background. |
324| <a id="injectQueryFn-property-refetchonmount"></a> `refetchOnMount?` | \| `boolean` \| `"always"` \| ((`query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, `TQueryFnData`, `TQueryKey`\>) => `boolean` \| `"always"`) | `true` | If set to `true`, the query will refetch on mount if the data is stale. If set to `false`, will disable additional instances of a query to trigger background refetch. If set to `'always'`, the query will always refetch on mount (except when `staleTime: 'static'` is used). If set to a function, the function will be executed with the latest data and query to compute the value |
325| <a id="injectQueryFn-property-refetchonreconnect"></a> `refetchOnReconnect?` | \| `boolean` \| `"always"` \| ((`query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, `TQueryFnData`, `TQueryKey`\>) => `boolean` \| `"always"`) | `undefined` | If set to `true`, the query will refetch on reconnect if the data is stale. If set to `false`, the query will not refetch on reconnect. If set to `'always'`, the query will always refetch on reconnect (except when `staleTime: 'static'` is used). If set to a function, the function will be executed with the latest data and query to compute the value. Defaults to `true` unless `networkMode` is `'always'`. |
326| <a id="injectQueryFn-property-refetchonwindowfocus"></a> `refetchOnWindowFocus?` | \| `boolean` \| `"always"` \| ((`query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, `TQueryFnData`, `TQueryKey`\>) => `boolean` \| `"always"`) | `true` | If set to `true`, the query will refetch on window focus if the data is stale. If set to `false`, the query will not refetch on window focus. If set to `'always'`, the query will always refetch on window focus (except when `staleTime: 'static'` is used). If set to a function, the function will be executed with the latest data and query to compute the value. |
327| <a id="injectQueryFn-property-retry"></a> `retry?` | \| `number` \| `false` \| `true` \| ((`failureCount`: `number`, `error`: `TError`) => `boolean`) | `undefined` | If `false`, failed queries will not retry by default. If `true`, failed queries will retry infinitely. If set to an integer number, e.g. 3, failed queries will retry until the failed query count meets that number. If set to a function `(failureCount, error) => boolean` failed queries will retry until the function returns false. Defaults to `3` on the client and `0` on the server. |
328| <a id="injectQueryFn-property-retrydelay"></a> `retryDelay?` | `number` \| ((`failureCount`: `number`, `error`: `TError`) => `number`) | `undefined` | This function receives a `retryAttempt` integer and the actual Error and returns the delay to apply before the next attempt in milliseconds. A function like `attempt => Math.min(attempt > 1 ? 2 ** attempt * 1000 : 1000, 30 * 1000)` applies exponential backoff. A function like `attempt => attempt * 1000` applies linear backoff. Defaults to a function that applies exponential backoff, capped at 30 seconds. |
329| <a id="injectQueryFn-property-retryonmount"></a> `retryOnMount?` | \| `false` \| `true` \| ((`query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, `TQueryFnData`, `TQueryKey`\>) => `boolean`) | `true` | If set to `false`, the query will not be retried on mount if it contains an error. If set to a function, the function will be executed with the query to compute the value. |
330| <a id="injectQueryFn-property-select"></a> `select?` | (`data`: `TQueryFnData`) => `TData` | `undefined` | This option can be used to transform or select a part of the data returned by the query function. It affects the returned `data` value, but does not affect what gets stored in the query cache. The `select` function will only run if `data` changed, or if the reference to the `select` function itself changes. To optimize, memoize the function so its reference stays stable across calls. |
331| <a id="injectQueryFn-property-staletime"></a> `staleTime?` | \| `number` \| `"static"` \| ((`query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, `TQueryFnData`, `TQueryKey`\>) => `number` \| `"static"`) | `0` | The time in milliseconds after data is considered stale. If set to `Infinity`, the data will never be considered stale. If set to `'static'`, the data will never be considered stale. If set to a function, the function will be executed with the query to compute a `staleTime`. |
332| <a id="injectQueryFn-property-structuralsharing"></a> `structuralSharing?` | `boolean` \| ((`oldData`: `unknown`, `newData`: `unknown`) => `unknown`) | `true` | Set this to `false` to disable structural sharing between query results. Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom structural sharing logic. |
333| <a id="injectQueryFn-property-throwonerror"></a> `throwOnError?` | \| `false` \| `true` \| ((`error`: `TError`, `query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, `TQueryFnData`, `TQueryKey`\>) => `boolean`) | `false` | Whether errors should be thrown instead of setting the `error` property. If set to `true` or `suspense` is `true`, all errors will be thrown to the error boundary. If set to `false` and `suspense` is `false`, errors are returned as state. If set to a function, it will be passed the error and the query, and it should return a boolean indicating whether to show the error in an error boundary (`true`) or return the error as state (`false`). |
334β
335### options?
336β
337[`InjectQueryOptions`](../interfaces/InjectQueryOptions.md)
338β
339Additional configuration
340β
341<a id="options-properties"></a>
342β
343#### `options` properties
344β
345| Property | Type | Description |
346| ------ | ------ | ------ |
347| <a id="options-property-injector"></a> `injector?` | `Injector` | The `Injector` in which to create the query. If this is not provided, the current injection context will be used instead (via `inject`). |
348β
349<a id="returns-summary"></a>
350β
351## Returns
352β
353[`CreateQueryResult`](../type-aliases/CreateQueryResult.md)\<`TData`, `TError`\>
354β
355The query result.