new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

TanStack Query · Reference · all subjects

query options

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

queryOptions function usage in Angular

queryOptions is a function from @tanstack/angular-query-experimental that accepts an object with queryKey and queryFn properties and returns a query options object that can be reused across multiple places in an Angular application. The function returns an object that can be spread into injectQuery and used with queryClient methods.

queryKey and queryFn in queryOptions

queryOptions accepts an object containing queryKey (an array identifying the query) and queryFn (a function that returns the data, which can use dependency injection like HttpClient). The example shows queryKey as ['post', postId] and queryFn as an async function returning a Promise from lastValueFrom(http.get(...)).

Using queryOptions with injectQuery

queryOptions output can be passed to injectQuery by wrapping it in a function. This enables type inference for the query.data property based on the queryFn return type.

queryOptions spread with select for type inference

queryOptions can be spread into injectQuery and combined with other options like select. When select is provided, query.data will have the return type of the select function rather than the queryFn return type, and type inference works correctly.

noop utility from @tanstack/angular-query-experimental

noop is a utility function exported from @tanstack/angular-query-experimental that can be used as a no-operation catch handler, such as in queryClient.query(options).catch(noop) to suppress error handling.

Give your agent this brain