function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options): UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & object & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData, unknown>, TError>;Defined in: preact-query/src/infiniteQueryOptions.ts:169
You can generally pass everything to infiniteQueryOptions that you can also pass to useInfiniteQuery. These options can be shared across hooks and imperative APIs such as queryClient.infiniteQuery. options.queryKey is required and is the query key to generate options for.
This overload is selected when initialData is set.
TQueryFnData
TError = Error
TData = InfiniteData<TQueryFnData, unknown>
TQueryKey extends readonly unknown[] = readonly unknown[]
TPageParam = unknown
DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>
The DefinedInitialDataInfiniteOptions to use — everything you can pass to useInfiniteQuery, with initialData set.
The same options object, typed so that queryKey carries the inferred data type.
useInfiniteQuery to run an infinite query with these options.
See useInfiniteQuery for examples that fetch further pages, from a button click or automatically as the user scrolls.
import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/preact-query'
export const projectsOptions = infiniteQueryOptions({
queryKey: ['projects'],
queryFn: ({ pageParam }) => fetchProjects(pageParam),
initialPageParam: 0,
getNextPageParam: (lastPage) => lastPage.nextId,
initialData: { pages: [], pageParams: [] },
})
function Projects() {
// `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the
// list stays visible alongside the error.
const { data, isError, error } = useInfiniteQuery(projectsOptions)
return (
<div>
{isError ? <span>Error: {error.message}</span> : null}
<ul>
{data.pages.map((page) => page.projects.map((p) => <li key={p.id}>{p.name}</li>))}
</ul>
</div>
)
}function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options): OmitKeyof<UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, "queryFn"> & object & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData, unknown>, TError>;Defined in: preact-query/src/infiniteQueryOptions.ts:240
You can generally pass everything to infiniteQueryOptions that you can also pass to useInfiniteQuery. These options can be shared across hooks and imperative APIs such as queryClient.infiniteQuery. options.queryKey is required and is the query key to generate options for.
TQueryFnData
TError = Error
TData = InfiniteData<TQueryFnData, unknown>
TQueryKey extends readonly unknown[] = readonly unknown[]
TPageParam = unknown
UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>
The UnusedSkipTokenInfiniteOptions to use — everything you can pass to useInfiniteQuery.
The same options object, typed so that queryKey carries the inferred data type.
See useInfiniteQuery for examples that fetch further pages, from a button click or automatically as the user scrolls.
A parameterized factory, reused across a hook and an imperative call with the same cache entry:
import {
infiniteQueryOptions,
noop,
useInfiniteQuery,
} from '@tanstack/preact-query'
export const commentsOptions = (postId: string) =>
infiniteQueryOptions({
queryKey: ['post', postId, 'comments'],
queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
initialPageParam: 0,
getNextPageParam: (lastPage) => lastPage.nextId,
})
function Comments({ postId }: { postId: string }) {
const { data, isPending, isError, error } = useInfiniteQuery(commentsOptions(postId))
if (isPending) return 'Loading...'
if (isError) return <span>Error: {error.message}</span>
return (
<ul>
{data.pages.map((page) => page.comments.map((c) => <li key={c.id}>{c.text}</li>))}
</ul>
)
}
// `commentsOptions` also works with imperative APIs like `queryClient.infiniteQuery` —
// see `useInfiniteQuery` for an example that warms the cache this way before rendering `<Comments>`.
const postId = '1'
queryClient.infiniteQuery(commentsOptions(postId)).catch(noop)useInfiniteQuery to run an infinite query with these options.
function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options): UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & object & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData, unknown>, TError>;Defined in: preact-query/src/infiniteQueryOptions.ts:311
You can generally pass everything to infiniteQueryOptions that you can also pass to useInfiniteQuery. These options can be shared across hooks and imperative APIs such as queryClient.infiniteQuery. options.queryKey is required and is the query key to generate options for.
TQueryFnData
TError = Error
TData = InfiniteData<TQueryFnData, unknown>
TQueryKey extends readonly unknown[] = readonly unknown[]
TPageParam = unknown
UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>
The UndefinedInitialDataInfiniteOptions to use — everything you can pass to useInfiniteQuery.
The same options object, typed so that queryKey carries the inferred data type.
See useInfiniteQuery for examples that fetch further pages (from a button click or automatically as the user scrolls) and that use skipToken to disable the query until postId is set.
A parameterized factory, reused across a hook and an imperative call with the same cache entry:
import {
infiniteQueryOptions,
noop,
useInfiniteQuery,
} from '@tanstack/preact-query'
export const commentsOptions = (postId: string) =>
infiniteQueryOptions({
queryKey: ['post', postId, 'comments'],
queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
initialPageParam: 0,
getNextPageParam: (lastPage) => lastPage.nextId,
})
function Comments({ postId }: { postId: string }) {
const { data, isPending, isError, error } = useInfiniteQuery(commentsOptions(postId))
if (isPending) return 'Loading...'
if (isError) return <span>Error: {error.message}</span>
return (
<ul>
{data.pages.map((page) => page.comments.map((c) => <li key={c.id}>{c.text}</li>))}
</ul>
)
}
// `commentsOptions` also works with imperative APIs like `queryClient.infiniteQuery` —
// see `useInfiniteQuery` for an example that warms the cache this way before rendering `<Comments>`.
const postId = '1'
queryClient.infiniteQuery(commentsOptions(postId)).catch(noop)useInfiniteQuery to run an infinite query with these options.