const queryFn = (...queryKey, pageParam) // => Promiseconst {fetchNextPage,fetchPreviousPage,hasNextPage,hasPreviousPage,isFetchingNextPage,isFetchingPreviousPage,...result} = useInfiniteQuery(queryKey, queryFn, {...options,getNextPageParam: (lastPage, allPages) => lastPage.nextCursor,getPreviousPageParam: (firstPage, allPages) => firstPage.prevCursor})
Options
The options for useInfiniteQuery
are identical to the useQuery
hook with the addition of the following:
getNextPageParam: (lastPage, allPages) => unknown | undefined
undefined
to indicate there is no next page available.getPreviousPageParam: (firstPage, allPages) => unknown | undefined
undefined
to indicate there is no previous page available.Returns
The returned properties for useInfiniteQuery
are identical to the useQuery
hook, with the addition of the following:
isFetchingNextPage: boolean
true
while fetching the next page with fetchNextPage
.isFetchingPreviousPage: boolean
true
while fetching the previous page with fetchPreviousPage
.fetchNextPage: (options?: FetchNextPageOptions) => Promise<UseInfiniteQueryResult>
options.pageParam: unknown
allows you to manually specify a page param instead of using getNextPageParam
.fetchPreviousPage: (options?: FetchPreviousPageOptions) => Promise<UseInfiniteQueryResult>
options.pageParam: unknown
allows you to manually specify a page param instead of using getPreviousPageParam
.hasNextPage: boolean
true
if there is a next page to be fetched (known via the getNextPageParam
option).hasPreviousPage: boolean
true
if there is a previous page to be fetched (known via the getPreviousPageParam
option).The latest TanStack news, articles, and resources, sent to your inbox.