* docs(*): add parameter and result property tables to reference function pages and an overview to overloaded ones * docs(*): link to the base type's properties when a parameter or result type has no property table * docs(framework/*/reference): regenerate reference docs * docs(framework/*/reference): regenerate reference docs * chore(scripts/generate-docs): restore the 'dirname' import that the merge dropped * docs(framework/*/reference): regenerate reference docs * docs(scripts/generate-docs): label overloads in the overview with their declared parameter and return types * docs(framework/*/reference): regenerate reference docs * docs(scripts/generate-docs): convert declared intersection types from the source so signatures keep their alias names * docs(framework/*/reference): regenerate reference docs * docs(scripts/generate-docs): reword a comment to avoid the unknown word 'inlines' * docs(scripts/generate-docs): skip a parameter table on overloaded pages when its heading is missing
7.3 KiB
| id | title | redirect_from | |
|---|---|---|---|
| queryOptions | queryOptions |
|
Overview
function queryOptions<TQueryFnData, TError, TData, TQueryKey>(options: QueryOptions<TQueryFnData, TError, TData, TQueryKey> & object): ReturnType<DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
function queryOptions<TQueryFnData, TError, TData, TQueryKey>(options: QueryOptions<TQueryFnData, TError, TData, TQueryKey> & object): ReturnType<UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
ReturnType<DefinedInitialDataOptions>→ReturnType<DefinedInitialDataOptions> & QueryKeyWithDataTag: You can generally pass everything toqueryOptionsthat you can also pass touseQuery. These options can be shared across hooks and imperative APIs such asqueryClient.query.options.queryKeyis required and is the query key to generate options for.ReturnType<UndefinedInitialDataOptions>→ReturnType<UndefinedInitialDataOptions> & QueryKeyWithDataTag: You can generally pass everything toqueryOptionsthat you can also pass touseQuery. These options can be shared across hooks and imperative APIs such asqueryClient.query.options.queryKeyis required and is the query key to generate options for.
See also: Parameters · Returns
Call Signature
function queryOptions<TQueryFnData, TError, TData, TQueryKey>(options: QueryOptions<TQueryFnData, TError, TData, TQueryKey> & object): ReturnType<DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
Defined in: packages/solid-query/src/queryOptions.ts:86
You can generally pass everything to queryOptions that you can also pass to useQuery. These options can
be shared across hooks and imperative APIs such as queryClient.query. options.queryKey is required and
is the query key to generate options for.
This overload is selected when initialData is set, so the resulting data is never undefined (unless
a select changes TData to include undefined).
Type Parameters
TQueryFnData
TQueryFnData = unknown
TError
TError = Error
TData
TData = TQueryFnData
TQueryKey
TQueryKey extends readonly unknown[] = readonly unknown[]
Parameters
options
QueryOptions<TQueryFnData, TError, TData, TQueryKey> & object
The DefinedInitialDataOptions to use — everything you can pass to useQuery, with initialData set.
Returns
ReturnType<DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>
The same options object, typed so that queryKey carries the inferred data type.
See
useQuery to run a query with these options.
Example
import { For } from 'solid-js'
import { queryOptions, useQuery } from '@tanstack/solid-query'
const postsOptions = queryOptions({
queryKey: ['posts'],
queryFn: fetchPosts,
initialData: [],
})
function Posts() {
// `postsQuery.data` is `Post[]`, never `undefined`, thanks to `initialData` — even if a refetch fails,
// so the list stays visible alongside the error.
const postsQuery = useQuery(() => postsOptions)
return (
<div>
{postsQuery.isError ? <span>Error: {postsQuery.error.message}</span> : null}
<ul>
<For each={postsQuery.data}>{(post) => <li>{post.title}</li>}</For>
</ul>
</div>
)
}
Call Signature
function queryOptions<TQueryFnData, TError, TData, TQueryKey>(options: QueryOptions<TQueryFnData, TError, TData, TQueryKey> & object): ReturnType<UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
Defined in: packages/solid-query/src/queryOptions.ts:134
You can generally pass everything to queryOptions that you can also pass to useQuery. These options can
be shared across hooks and imperative APIs such as queryClient.query. options.queryKey is required and
is the query key to generate options for.
Type Parameters
TQueryFnData
TQueryFnData = unknown
TError
TError = Error
TData
TData = TQueryFnData
TQueryKey
TQueryKey extends readonly unknown[] = readonly unknown[]
Parameters
options
QueryOptions<TQueryFnData, TError, TData, TQueryKey> & object
The UndefinedInitialDataOptions to use — everything you can pass to useQuery.
Returns
ReturnType<UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>
The same options object, typed so that queryKey carries the inferred data type.
See
useQuery to run a query with these options.
Example
A parameterized factory, so the same options object can be reused per id:
import { Match, Switch } from 'solid-js'
import { queryOptions, useQuery } from '@tanstack/solid-query'
const postOptions = (id: string) =>
queryOptions({
queryKey: ['post', id],
queryFn: () => fetchPost(id),
})
function Post(props: { id: string }) {
const postQuery = useQuery(() => postOptions(props.id))
return (
<Switch>
<Match when={postQuery.isPending}>Loading...</Match>
<Match when={postQuery.isError}>Error: {postQuery.error.message}</Match>
<Match when={postQuery.isSuccess}>
<h1>{postQuery.data.title}</h1>
</Match>
</Switch>
)
}
Parameters
options
QueryOptions<TQueryFnData, TError, TData, TQueryKey> & object
The UndefinedInitialDataOptions to use — everything you can pass to useQuery.
options properties
Built from QueryOptions. See the type above for what it changes.
Returns
ReturnType<UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>
The same options object, typed so that queryKey carries the inferred data type.
Result properties
Built from QueryOptions, QueryKeyWithDataTag. See the type above for what it changes.