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
const { queryKey } = queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(5),
// ^? Promise<number>
})
const queryClient = new QueryClient()
const data = queryClient.getQueryData(queryKey)
// ^? number | undefined
The query options to tag with the type from queryFn.
function queryOptions<TQueryFnData, TError, TData, TQueryKey>(
options,
): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & object
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
const { queryKey } = queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(5),
// ^? Promise<number>
})
const queryClient = new QueryClient()
const data = queryClient.getQueryData(queryKey)
// ^? number | undefined
• TQueryFnData = unknown
• TError = Error
• TData = TQueryFnData
• TQueryKey extends QueryKey = QueryKey
• options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
The query options to tag with the type from queryFn.
UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & object
The tagged query options.
The tagged query options.
The query options to tag with the type from queryFn.
function queryOptions<TQueryFnData, TError, TData, TQueryKey>(
options,
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & object
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
const { queryKey } = queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(5),
// ^? Promise<number>
})
const queryClient = new QueryClient()
const data = queryClient.getQueryData(queryKey)
// ^? number | undefined
• TQueryFnData = unknown
• TError = Error
• TData = TQueryFnData
• TQueryKey extends QueryKey = QueryKey
• options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
The query options to tag with the type from queryFn.
DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & object
The tagged query options.
The tagged query options.
The query options to tag with the type from queryFn.