id: queryOptions
title: queryOptions
Function: queryOptions()
Allows to share and re-use query options in a type-safe way.
The queryKey will be tagged with the type from queryFn.
Example
const { queryKey } = queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(5),
// ^? Promise<number>
})
const queryClient = new QueryClient()
const data = queryClient.getQueryData(queryKey)
// ^? number | undefined
Param
The query options to tag with the type from queryFn.
Call Signature
function queryOptions<TQueryFnData, TError, TData, TQueryKey>(
options,
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & object
Allows to share and re-use query options in a type-safe way.
The queryKey will be tagged with the type from queryFn.
Example
const { queryKey } = queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(5),
// ^? Promise<number>
})
const queryClient = new QueryClient()
const data = queryClient.getQueryData(queryKey)
// ^? number | undefined
Type Parameters
• TQueryFnData = unknown
• TError = Error
• TData = TQueryFnData
• TQueryKey extends readonly unknown[] = readonly unknown[]
Parameters
options
DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
The query options to tag with the type from queryFn.
Returns
DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & object
The tagged query options.
The tagged query options.
Param
The query options to tag with the type from queryFn.
Defined in
Call Signature
function queryOptions<TQueryFnData, TError, TData, TQueryKey>(
options,
): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> & object
Allows to share and re-use query options in a type-safe way.
The queryKey will be tagged with the type from queryFn.
Example
const { queryKey } = queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(5),
// ^? Promise<number>
})
const queryClient = new QueryClient()
const data = queryClient.getQueryData(queryKey)
// ^? number | undefined
Type Parameters
• TQueryFnData = unknown
• TError = Error
• TData = TQueryFnData
• TQueryKey extends readonly unknown[] = readonly unknown[]
Parameters
options
UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>
The query options to tag with the type from queryFn.
Returns
UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> & object
The tagged query options.
The tagged query options.
Param
The query options to tag with the type from queryFn.
Defined in
Call Signature
function queryOptions<TQueryFnData, TError, TData, TQueryKey>(
options,
): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & object
Allows to share and re-use query options in a type-safe way.
The queryKey will be tagged with the type from queryFn.
Example
const { queryKey } = queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(5),
// ^? Promise<number>
})
const queryClient = new QueryClient()
const data = queryClient.getQueryData(queryKey)
// ^? number | undefined
Type Parameters
• TQueryFnData = unknown
• TError = Error
• TData = TQueryFnData
• TQueryKey extends readonly unknown[] = readonly unknown[]
Parameters
options
UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
The query options to tag with the type from queryFn.
Returns
UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & object
The tagged query options.
The tagged query options.
Param
The query options to tag with the type from queryFn.