Playground API
DocsStatsBlogStudio
Playground API

The free, stateful mock REST & GraphQL API sandbox where visitor mutations actually persist in an isolated session overlay without sign-up.

Public API Online (99.98%)

Endpoints

  • /api/v1/posts
  • /api/v1/users
  • /api/v1/comments
  • /api/v1/todos
  • /api/v1/graphql

Simulations

  • JWT Auth & Roles
  • Stripe Payments
  • Virtual Email & OTP
  • Latency & Chaos
  • Realtime Webhooks

Articles & Guides

Deep Dives
  • All Feature Articles→
  • React CRUD Guide
  • Why Static APIs Fail
  • Mocking Stateful Auth
  • WebSockets & SSE

Ecosystem

  • Quickstart Guide
  • TypeScript SDK
  • OpenAPI Spec
  • Postman Collection
  • GitHub Repository

Ā© 2026 Playground API. Created by Nilesh Kumar. Open source under ISC license.

Powered by Express 5, Prisma & Neon PostgreSQLllms.txt
HomeBlogHow to Test Cursor-Based Pagination & Infinite Scroll in React Without a Backend
Feature Deep Dive1 min read•2026-09-20

How to Test Cursor-Based Pagination & Infinite Scroll in React Without a Backend

Learn how to test cursor-based pagination, opaque base64 tokens, React Query useInfiniteQuery, and infinite scroll feeds using Playground API.

NK
Nilesh Kumar
Creator of Playground API
How to Test Cursor-Based Pagination & Infinite Scroll in React Without a Backend

How to Test Cursor-Based Pagination & Infinite Scroll in React Without a Backend

Standard offset-based pagination (?page=2&limit=10) works fine for simple tables, but for modern infinite scroll feeds (Twitter, Instagram, Reddit style), offset pagination fails because:

  • New items inserted at the top shift the entire list, causing duplicate items or skipped entries when scrolling down.
  • Database OFFSET queries degrade severely on large datasets.

Modern production APIs use Cursor-Based Pagination (?cursor=<base64>&limit=10), returning a pointer to the last item seen (nextCursor) and a boolean hasMore flag.

Playground API now provides native Cursor-Based Pagination across all endpoints!


1. The Cursor Endpoint Contract

Make a request with cursor and limit:

Terminal
curl "https://playground.nileslabs.com/posts?cursor=eyJpZCI6MTB9&limit=10"

JSON Response:

json
1
{
2
"data": [
3
{ "id": 11, "title": "Next Post Title", "body": "..." },
4
{ "id": 12, "title": "Another Post", "body": "..." }
5
],
6
"pagination": {
7
"nextCursor": "eyJpZCI6MjB9",
8
"hasMore": true,
9
"total": 100
10
}
11
}

When reaching the end of the collection, hasMore returns false and nextCursor returns null.


2. Integrating with TanStack React Query (useInfiniteQuery)

tsx
1
import { useInfiniteQuery } from '@tanstack/react-query';
2
3
async function fetchPosts({ pageParam = null }: { pageParam?: string | null }) {
4
const url = pageParam
5
? https://playground.nileslabs.com/posts?cursor=${pageParam}&limit=10`
6
: 'https://playground.nileslabs.com/posts?limit=10';
7
8
const res = await fetch(url);
9
return res.json();
10
}
11
12
export function InfiniteFeed() {
13
const {
14
data,
15
fetchNextPage,
16
hasNextPage,
17
isFetchingNextPage,
18
} = useInfiniteQuery({
19
queryKey: ['infinite-posts'],
20
queryFn: fetchPosts,
21
getNextPageParam: (lastPage) => lastPage.pagination.nextCursor,
22
initialPageParam: null,
23
});
24
25
return (
26
<div>
27
{data?.pages.map((page, i) => (
28
<div key={i}>
29
{page.data.map((post: any) => (
30
<div key={post.id} className="post-card">
31
<h4>{post.title}</h4>
32
</div>
33
))}
34
</div>
35
))}
36
37
{hasNextPage && (
38
<button onClick={() => fetchNextPage()} disabled={isFetchingNextPage}>
39
{isFetchingNextPage ? 'Loading more...' : 'Load More'}
40
</button>
41
)}
42
</div>
43
);
44
}

3. Interactive Pagination Studio

Explore cursor tokens, page parameters, and infinite scrolling in the documentation:

šŸ‘‰ https://playground.nileslabs.com/docs/pagination


Conclusion

Test real infinite scroll feeds and TanStack Query caching seamlessly with Playground API!

Tags:#react#webdev#javascript#frontend
Continue Reading
Previous Article
Shareable Sandbox URLs & Cross-Device Mobile QR Sync in Playground API
Next Article
Introducing the Official Zero-Dependency TypeScript SDK for Playground API

Try Playground API in Your Own App

Stateful mock REST & GraphQL API with private sandbox overlays.

Quickstart GuideOpen Interactive Studio
Table of Contents
0%
  • 1. The Cursor Endpoint Contract
  • JSON Response:
  • 2. Integrating with TanStack React Query (useInfiniteQuery)
  • 3. Interactive Pagination Studio
  • Conclusion
Feature Deep Dives

In-depth technical guides exploring Playground API features — real-time subscriptions, stateful sandboxes, schema validation, latency simulation, and developer tooling.

Browse All Articles