refactor: Update Pagination component to ensure hooks are called unconditionally and improve early return logic for better performance and readability.
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m49s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m49s
This commit is contained in:
@@ -7,10 +7,10 @@ import { IconChevronLeft, IconChevronRight, IconChevronsLeft, IconChevronsRight
|
||||
*/
|
||||
function Pagination({ currentPage, totalPages, totalItems, pageSize, onPageChange }) {
|
||||
const [jumpToPage, setJumpToPage] = useState('');
|
||||
|
||||
if (totalPages <= 1) return null;
|
||||
|
||||
// Хуки должны вызываться безусловно (до любого return)
|
||||
const pages = useMemo(() => {
|
||||
if (totalPages <= 1) return [];
|
||||
const result = [];
|
||||
let start = Math.max(1, currentPage - 2);
|
||||
let end = Math.min(totalPages, currentPage + 2);
|
||||
@@ -31,6 +31,9 @@ function Pagination({ currentPage, totalPages, totalItems, pageSize, onPageChang
|
||||
return result;
|
||||
}, [currentPage, totalPages]);
|
||||
|
||||
// Ранний return после всех хуков
|
||||
if (totalPages <= 1) return null;
|
||||
|
||||
const startItem = (currentPage - 1) * pageSize + 1;
|
||||
const endItem = Math.min(currentPage * pageSize, totalItems);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user