Pagination Component
The <Pagination> component renders previous/next buttons and the page numbers between them. It is the same pagination used in the footer of the <Table> component.
Basic Usage
The number of pages is calculated from itemsLength and itemsPerPage, or can be passed directly with pageCount.
- From Items
- Page Count
import { Pagination } from "react-better-html";
function App() {
return (
<Pagination
itemsLength={240}
itemsPerPage={20}
onChangePage={(page) => console.log("Current page:", page)}
/>
);
}
import { useState } from "react";
import { Pagination } from "react-better-html";
function App() {
const [page, setPage] = useState(1);
return (
<Pagination
pageCount={50}
currentPage={page}
onChangePage={setPage}
/>
);
}
Common Props
currentPage- the selected page (defaults to1). Changing it from outside updates the componentitemsLength/itemsPerPage- used to calculate the number of pagespageCount- the number of pages (takes precedence overitemsLengthanditemsPerPage)maximumVisiblePages- how many page numbers are visible at once (defaults to11)onChangePage- called with the new page every time it changesonClickPreviousPage/onClickNextPage- called with the new page when the arrow buttons are clicked