Skip to main content

Search

Search problems, hooks, and pages

Pagination Component

Build a pagination control that splits a large dataset into pages and lets the user navigate between them.

Requirements

  • Display a configurable number of items per page (5, 10, 20)
  • Show previous / next buttons (disabled at boundaries)
  • Show direct page number buttons with the current page highlighted
  • Display "Showing X–Y of Z items" status text
  • Changing items-per-page resets to page 1

Key Patterns

Math.ceil(total / perPage)Array.slice(start, end)Derived start/end indicesControlled select for perPageBoundary disabling

Important

Interview Tip

Key formula: startIndex = (currentPage - 1) * itemsPerPage. endIndex = startIndex + itemsPerPage. currentItems = data.slice(startIndex, endIndex). Never store currentItems in state — derive it from currentPage + itemsPerPage + data.
Showing 15 of 47 users
IDNameRoleStatus
1User 001Frontend DevInactive
2User 002Backend DevActive
3User 003DesignerActive
4User 004DevOpsInactive
5User 005PMActive