This commit is contained in:
Malai Raja
2023-11-27 17:09:27 +05:30
commit 7113ac0681
223 changed files with 56261 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import { useState } from 'react';
// ==============================|| CARD - PAGINATION ||============================== //
export default function usePagination(data, itemsPerPage) {
const [currentPage, setCurrentPage] = useState(1);
const maxPage = Math.ceil(data.length / itemsPerPage);
function currentData() {
const begin = (currentPage - 1) * itemsPerPage;
const end = begin + itemsPerPage;
return data.slice(begin, end);
}
function next() {
setCurrentPage((currentPage) => Math.min(currentPage + 1, maxPage));
}
function prev() {
setCurrentPage((currentPage) => Math.max(currentPage - 1, 1));
}
function jump(page) {
const pageNumber = Math.max(1, page);
setCurrentPage(() => Math.min(pageNumber, maxPage));
}
return { next, prev, jump, currentData, currentPage, maxPage };
}