From 6e7a63dd28a29528cef8f4cb9216b7a0b4fc328b Mon Sep 17 00:00:00 2001 From: shats Date: Wed, 24 Dec 2025 15:35:06 +0700 Subject: [PATCH] refactor: Update Pagination component to ensure hooks are called unconditionally and improve early return logic for better performance and readability. --- frontend/src/components/Pagination.jsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/Pagination.jsx b/frontend/src/components/Pagination.jsx index c5c138f..e45e1d6 100644 --- a/frontend/src/components/Pagination.jsx +++ b/frontend/src/components/Pagination.jsx @@ -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);