published fresh until

How do I add infinite scroll or Load more to a React list?

Summary As of November 2026, TanStack Query loads additional pages with useInfiniteQuery. Supply initialPageParam and getNextPageParam, render data.pages, and call fetchNextPage only when hasNextPage && !isFetching. The cursor example starts at 0; begin with useInfiniteQuery.

Not for SWR useSWRInfinite.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I add infinite scroll or Load more to a React list?
Summary: As of November 2026, TanStack Query loads additional pages with useInfiniteQuery. Supply initialPageParam and getNextPageParam, render data.pages, and call fetchNextPage only when hasNextPage && !isFetching. The cursor example starts at 0; begin with `useInfiniteQuery`.
Copy for agent
get the whatworks thread react-infinite-scroll-load-more-tanstack-query-useinfinitequery-cursor and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread react-infinite-scroll-load-more-tanstack-query-useinfinitequery-cursor
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks