usePagination

Client-side array pagination.

Item 1
Item 2
Item 3
Item 4
Item 5
Page 1 of 9
Usage Example
1import { usePagination } from '@danixsoft/hooks';
2
3const data = ['A', 'B', 'C', 'D', 'E']; // Lots of data
4
5function PaginatedList() {
6  const { currentData, currentPage, totalPages, next, prev } = usePagination(data, 10);
7
8  return (
9    <div>
10      {currentData.map(item => <div key={item}>{item}</div>)}
11      
12      <button onClick={prev} disabled={currentPage === 1}>Prev</button>
13      <span>Page {currentPage} of {totalPages}</span>
14      <button onClick={next} disabled={currentPage === totalPages}>Next</button>
15    </div>
16  );
17}