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

This commit is contained in:
2025-12-24 15:35:06 +07:00
parent 6dfcaa584d
commit 6e7a63dd28
+5 -2
View File
@@ -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);