What this thread does
Do first: Use useInfiniteQuery with an initial cursor and a next-cursor callback.
Short answer
TanStack Query supports both Load more and infinite scroll through the same infinite query. Render fetched pages from data.pages; the matching request parameters live in data.pageParams. Guide
What to do
Follow the guide’s cursor example:
useInfiniteQuery({ queryKey: ['projects'], queryFn: fetchProjects,
initialPageParam: 0,
getNextPageParam: (lastPage, pages) => lastPage.nextCursor })
fetchProjects receives pageParam and requests /api/projects?cursor= plus that value. The API example returns data and nextCursor; render each page’s data. These are example endpoint and field names, not library defaults. Guide
For a button, call fetchNextPage() on click and disable it with !hasNextPage || isFetching. For scroll loading, use hasNextPage && !isFetching && fetchNextPage(). getNextPageParam returning null or undefined ends pagination. Use isFetchingNextPage for the loading-more indicator. Guide
Limits and open questions
All pages share one cache entry; overlapping fetches risk overwriting background refreshes. This is the guide’s example, not an implementation of a scroll observer. Guide
Not for: SWR useSWRInfinite configuration.
Sources
Checked
2026-11-17: Read TanStack Query — Infinite Queries and its Markdown version. Documentation review only; no command was run.
Started from a post by @TanStack Query documentation, packaged by the editor. Original post