pref: 代码优化
This commit is contained in:
@@ -18,12 +18,12 @@ import {
|
||||
} from '@chakra-ui/icons';
|
||||
|
||||
/**
|
||||
* 分页控制器组件
|
||||
* 分页控制器组件(使用 React.memo 优化,避免不必要的重新渲染)
|
||||
* @param {number} currentPage - 当前页码
|
||||
* @param {number} totalPages - 总页数
|
||||
* @param {Function} onPageChange - 页码改变回调
|
||||
*/
|
||||
const PaginationControl = ({ currentPage, totalPages, onPageChange }) => {
|
||||
const PaginationControl = React.memo(({ currentPage, totalPages, onPageChange }) => {
|
||||
const [jumpPage, setJumpPage] = useState('');
|
||||
const toast = useToast();
|
||||
|
||||
@@ -206,6 +206,10 @@ const PaginationControl = ({ currentPage, totalPages, onPageChange }) => {
|
||||
</HStack>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
}, (prevProps, nextProps) => {
|
||||
// 自定义比较函数:只有当 currentPage 或 totalPages 变化时才重新渲染
|
||||
return prevProps.currentPage === nextProps.currentPage &&
|
||||
prevProps.totalPages === nextProps.totalPages;
|
||||
});
|
||||
|
||||
export default PaginationControl;
|
||||
|
||||
Reference in New Issue
Block a user