
Product
Socket Brings Supply Chain Security to skills.sh
Socket is now scanning AI agent skills across multiple languages and ecosystems, detecting malicious behavior before developers install, starting with skills.sh's 60,000+ skills.
pagination-react-js
Advanced tools
React Pagination Hook, which is lightweight, fast and easy to use.
https://serhat-m.github.io/pagination-react-js
Fully customizable pagination example:
type PaginationItemProps = {
children: React.ReactNode
label: React.ComponentProps<"button">["aria-label"]
active?: boolean
onClick: React.ComponentProps<"button">["onClick"]
}
const PaginationItem = ({ children, label, active, onClick }: PaginationItemProps) => {
return (
<li>
<button
type="button"
className={["pagination-item", active ? "pagination-item-active" : undefined].filter((value) => value).join(" ")}
onClick={onClick}
aria-current={active}
aria-label={label}
>
{children}
</button>
</li>
)
}
const PaginatedTable = () => {
const dataList = useMemo(
() =>
Array.from({ length: 500 }, (_, index) => ({
id: index,
name: `Test ${index}`,
gender: index % 2 ? "Female" : "Male",
position: `Position ${index}`,
email: `test${index}@test.com`,
})),
[],
)
const { records, pagination, setActivePage, setRecordsPerPage } = usePagination({
activePage: 1,
recordsPerPage: 10,
totalRecordsLength: dataList.length,
offset: 2,
navCustomPageSteps: { prev: 3, next: 3 },
permanentFirstNumber: true,
permanentLastNumber: true,
})
function updateActivePage(pageNumber: number | null) {
if(pageNumber) setActivePage(pageNumber)
}
return (
<div>
<table>
<tbody>
{dataList.slice(records.indexOfFirst, records.indexOfLast + 1).map((record) => {
return (
<tr key={record.id}>
<td>{record.id}</td>
<td>{record.name}</td>
</tr>
)
})}
</tbody>
</table>
{pagination && (
<nav aria-label="Page navigation">
<ul className="pagination">
<PaginationItem label={`Goto first page ${pagination.firstPage}`} onClick={() => updateActivePage(pagination.firstPage)}>
«
</PaginationItem>
<PaginationItem label={`Goto previous page ${pagination.previousPage}`} onClick={() => updateActivePage(pagination.previousPage)}>
‹
</PaginationItem>
<PaginationItem
label={`Goto first page ${pagination.firstPage}`}
active={pagination.firstPage === pagination.activePage}
onClick={() => updateActivePage(pagination.firstPage)}
>
{pagination.firstPage}
</PaginationItem>
{pagination.customPreviousPage && (
<PaginationItem label={`Goto page ${pagination.customPreviousPage}`} onClick={() => updateActivePage(pagination.customPreviousPage)}>
···
</PaginationItem>
)}
{pagination.pageNumbers.map((paginationNumber) => {
const isFirstOrLastPage = paginationNumber === pagination.firstPage || paginationNumber === pagination.lastPage
return isFirstOrLastPage ? null : (
<PaginationItem
label={`Goto page ${paginationNumber}`}
key={paginationNumber}
active={paginationNumber === pagination.activePage}
onClick={() => updateActivePage(paginationNumber)}
>
{paginationNumber}
</PaginationItem>
)
})}
{pagination.customNextPage && (
<PaginationItem label={`Goto page ${pagination.customNextPage}`} onClick={() => updateActivePage(pagination.customNextPage)}>
···
</PaginationItem>
)}
{pagination.firstPage !== pagination.lastPage && (
<PaginationItem
label={`Goto last page ${pagination.lastPage}`}
active={pagination.lastPage === pagination.activePage}
onClick={() => updateActivePage(pagination.lastPage)}
>
{pagination.lastPage}
</PaginationItem>
)}
<PaginationItem label={`Goto next page ${pagination.nextPage}`} onClick={() => updateActivePage(pagination.nextPage)}>
›
</PaginationItem>
<PaginationItem label={`Goto last page ${pagination.lastPage}`} onClick={() => updateActivePage(pagination.lastPage)}>
»
</PaginationItem>
</ul>
</nav>
)}
</div>
)
}
:root {
font-size: 16px;
--border-size: 0.125rem;
--border-radius: 0.3rem;
--color-gray: #e1e4e7;
--color-active: #0a7ea3;
}
.pagination {
display: flex;
flex-direction: row;
justify-content: center;
gap: 0.5rem;
width: fit-content;
list-style-type: none;
padding: 0.5rem 0.625rem;
border: var(--border-size) solid var(--color-gray);
border-radius: var(--border-radius);
user-select: none;
}
.pagination-item {
width: 2rem;
height: 2rem;
display: flex;
align-items: center;
justify-content: center;
border-radius: var(--border-radius);
}
.pagination-item:hover {
cursor: pointer;
background-color: var(--color-gray);
}
.pagination-item-active {
color: white;
background-color: var(--color-active);
pointer-events: none;
}
usePagination(options: TFnOptions): TPaginationDatatype TFnOptionsexport type TFnOptions = {
activePage: number
recordsPerPage: number
totalRecordsLength: number
offset: number
navCustomPageSteps?: { prev?: number; next?: number }
permanentFirstNumber?: boolean
permanentLastNumber?: boolean
}
type TPaginationDataexport type TPaginationData = {
readonly records: {
perPage: number
indexOfFirst: number
indexOfLast: number
}
readonly pagination: {
activePage: number
firstPage: number
lastPage: number
previousPage: number | null
nextPage: number | null
customPreviousPage: number | null
customNextPage: number | null
pageNumbers: number[]
} | null
readonly setActivePage: (pageNumber: number) => void
readonly setRecordsPerPage: (recordsPerPage: number) => void
}
FAQs
React Pagination Hook, which is lightweight, fast and easy to use.
The npm package pagination-react-js receives a total of 647 weekly downloads. As such, pagination-react-js popularity was classified as not popular.
We found that pagination-react-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket is now scanning AI agent skills across multiple languages and ecosystems, detecting malicious behavior before developers install, starting with skills.sh's 60,000+ skills.

Product
Socket now supports PHP with full Composer and Packagist integration, enabling developers to search packages, generate SBOMs, and protect their PHP dependencies from supply chain threats.

Security News
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.