Skip to main content

Pagination

Use Pagination to display a sequence of links that allow navigation to discrete, related pages.

Ready to use
import {Pagination} from '@primer/react-brand'

Examples

Default

const App = () => { const [currentPage, setCurrentPage] = React.useState(5) const totalPages = 10 const handlePageChange = (e, pageNumber) => { if (pageNumber === currentPage + 1 && currentPage < totalPages) { // Next page handler setCurrentPage(currentPage + 1) } else if (pageNumber === currentPage - 1 && currentPage > 1) { // Previous page handler setCurrentPage(currentPage - 1) } else if (pageNumber >= 1 && pageNumber <= totalPages) { setCurrentPage(pageNumber) } } return <Pagination pageCount={10} currentPage={currentPage} onPageChange={handlePageChange} /> } render(<App />)

Hide page numbers

<Pagination pageCount={15} currentPage={5} showPages={false} />

Custom href

<Pagination pageCount={3} currentPage={1} hrefBuilder={n => `https://primer.style/brand/page/${n}`} />

Custom data attributes

<Pagination
  pageCount={3}
  currentPage={1}
  pageAttributesBuilder={n => {
    return {
      'data-custom-attribute': `custom-attribute-${n}`,
    }
  }}
/>

Component props

Pagination Required

nametypedefaultrequireddescription
pageCountnumbertrueThe total number of pages
currentPagenumbertrueThe current page number
onPageChange(e: React.MouseEvent, n: number) => voidfalseCallback function for when the page changes
hrefBuilder(n: number) => stringfalseFunction to build the href for each page
pageAttributesBuilder(n: number) => {[attributeName: string]: string}falseForward custom attributes to pagination links.
marginPageCountnumberfalseDefines how many pages are to be displayed on the left and right of the component. Will be reduced on narrow viewports.
showPagesbooleanfalseWhether to show the page numbers
surroundingPageCountnumberfalseThe number of pages to show on each side of the current page. Will be hidden on narrow viewports.