The usePagination hook provides full control over the pagination logic and item array. Use this hook when you need:
- A non-standard pagination UI.
- Integration with custom logic.
- Complex transition animations.
The hook returns an array of items representing the pages and ellipsis markers (e.g., [1, 'start-ellipsis', 4, 5, 6, 'end-ellipsis', 10]).
const items = usePagination({
totalPages: 10,
currentPage: 5,
});
// items → [1, 'start-ellipsis', 4, 5, 6, 'end-ellipsis', 10]
return (
<nav>
{items.map((item) =>
item === 'start-ellipsis' || item === 'end-ellipsis' ? (
<span key={item}>...</span>
) : (
<button key={item}>{item}</button>
),
)}
</nav>
);