Skip to content

Pagination

The Pagination component allows navigation through pages of content, with “Previous” and “Next” buttons and — in determinate mode — a page-size selector.

There are two modes:

  • Determinate — pass totalItems and pageSize so the component knows how many pages exist.
  • Indeterminate — pass indeterminate with hasNext / hasPrevious when the total isn’t known ahead of time; only the Next / Previous controls render.

Variations

Determinate pagination with page size select

Determinate pagination with custom page size values

The default page-size options are [10, 25, 50].

Indeterminate pagination with callbacks

Indeterminate pagination with callbacks and page select

Installation

Determinate pagination

import { Pagination } from '@harnessio/ui/components'
//...
const [currentPage, setCurrentPage] = useState(1)
return (
<Pagination
totalItems={100}
pageSize={10}
currentPage={currentPage}
goToPage={setCurrentPage}
/>
)

Indeterminate pagination

import { Pagination } from '@harnessio/ui/components'
//...
const [currentPage, setCurrentPage] = useState(1)
return (
<Pagination
indeterminate
hasPrevious={currentPage > 1}
hasNext={currentPage < 100}
currentPage={currentPage}
// if need to use links
getPrevPageLink={() => currentPage - 1}
getNextPageLink={() => currentPage + 1}
// if need to use buttons
onPrevious={() => setCurrentPage(currentPage - 1)}
onNext={() => setCurrentPage(currentPage + 1)}
/>
)