Skip to the page

Search, lists and data · core

Pagination component

A pagination component reads the current page from the URL, computes the page list with ellipses, disables Previous and Next at the ends, marks the current page with aria-current, resets to page 1 when filters change, and keeps the old rows visible while the next page loads.

The notes

What you must know

  • Page in the URL (?page=3) so refresh, share and Back work; totalPages = Math.ceil(total / pageSize).
  • Range with ellipses: always first and last, current ± siblings; show the missing page instead of '…' when only one page is hidden.
  • Markup: <nav aria-label='Pagination'> with buttons/links; aria-current='page' on the current one; Previous/Next disabled at the ends.
  • Reset to page 1 when search or filters change; clamp an out-of-range page.
  • Loading: keep the previous rows (dimmed) until the new page arrives, so the table doesn't jump; ignore stale responses.
  • Server vs client pagination: client-side only for small datasets; the server returns { items, total } (offset) or { items, nextCursor } ('Load more').
  • Page-size selector; scroll to the top of the list on page change; keyboard focus stays sensible.

The red pen

Common traps: mistake → fix

  • Mistake: Keep the page in component state only

    Fix: lost on refresh and Back.

  • Mistake: Forget to reset the page after a new search

    Fix: 'page 7 of 2' and an empty table.

  • Mistake: Render all 500 page buttons

    Fix: use ellipses.

Easy to hard

Questions interviewers ask, easy to hard

  1. Build pagination for this API with search.
  2. Show page numbers with ellipses for 100 pages.
  3. What happens to the page when the search changes?
  4. Offset pages or a 'Load more' cursor here?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview