Resource Library

Sanity GROQ Pagination with Slice + Total Count

Fetch paged items with GROQ slice while also retrieving total counts, and keep a safe fallback for local/dev.

Scroll
12 Apr 2025
5 min read
Fetch paged items with GROQ slice while also retrieving total counts, and keep a safe fallback for local/dev.

Use two queries: a count query for total and a slice query for the page window. When Sanity is missing or returns empty, fall back to hardcoded content so routes remain stable in CI and local development.

Next.js
React
TypeScript
Tailwind
AB
AlterByte Strategy Team
Digital Delivery Experts