diff --git a/src/components/PaginatedRow.tsx b/src/components/PaginatedRow.tsx index 5a67bdb..c2ec144 100644 --- a/src/components/PaginatedRow.tsx +++ b/src/components/PaginatedRow.tsx @@ -1,7 +1,7 @@ 'use client'; import { ChevronLeft, ChevronRight } from 'lucide-react'; -import { useMemo, useState } from 'react'; +import { useId, useMemo, useState } from 'react'; interface PaginatedRowProps { children: React.ReactNode[]; @@ -15,6 +15,7 @@ export default function PaginatedRow({ className = '', }: PaginatedRowProps) { const [currentPage, setCurrentPage] = useState(0); + const uniqueId = useId(); // 为每个实例生成唯一ID // 计算总页数 const totalPages = Math.ceil(children.length / itemsPerPage); @@ -26,73 +27,70 @@ export default function PaginatedRow({ return children.slice(startIndex, endIndex); }, [children, currentPage, itemsPerPage]); - // 是否显示左右按钮 - const showLeftButton = currentPage > 0; - const showRightButton = currentPage < totalPages - 1; - + // 无限循环翻页 const handlePrevPage = () => { - if (currentPage > 0) { - setCurrentPage(currentPage - 1); - } + setCurrentPage((prev) => (prev === 0 ? totalPages - 1 : prev - 1)); }; const handleNextPage = () => { - if (currentPage < totalPages - 1) { - setCurrentPage(currentPage + 1); - } + setCurrentPage((prev) => (prev === totalPages - 1 ? 0 : prev + 1)); }; // 如果没有足够的内容需要分页,就不显示按钮 const needsPagination = totalPages > 1; return ( -