From 8890e87bbd5f083c46c4959a8bf52b8f0dbbe277 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Wed, 26 Jul 2023 14:11:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20replace=20defaultProps=20?= =?UTF-8?q?with=20useDefaultProps=20(#2376)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 🐛 replace defaultProps with useDefaultProps * fix: 🐛 fix --- src/pagination/Pagination.tsx | 9 ++++++--- src/pagination/PaginationMini.tsx | 32 ++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/pagination/Pagination.tsx b/src/pagination/Pagination.tsx index 11146b3335..c35969c321 100644 --- a/src/pagination/Pagination.tsx +++ b/src/pagination/Pagination.tsx @@ -18,6 +18,7 @@ import { TdPaginationProps } from './type'; import { StyledProps } from '../common'; import { pageSizeValidator } from './validators'; import { paginationDefaultProps } from './defaultProps'; +import useDefaultProps from '../hooks/useDefaultProps'; export type { PageInfo } from './type'; @@ -25,7 +26,8 @@ export interface PaginationProps extends TdPaginationProps, StyledProps {} const { Option } = Select; -const Pagination = forwardRef((props: PaginationProps, ref: React.Ref) => { +const Pagination = forwardRef((originalProps, ref) => { + const props = useDefaultProps(originalProps, paginationDefaultProps); const { theme, size, @@ -69,7 +71,9 @@ const Pagination = forwardRef((props: PaginationProps, ref: React.Ref { - if (disabled || current === _nextCurrent) return; + if (disabled || current === _nextCurrent) { + return; + } let nextCurrent = _nextCurrent; let nextPageSize = _nextPageSize; @@ -219,6 +223,5 @@ const Pagination = forwardRef((props: PaginationProps, ref: React.Ref) => { +const PaginationMini = forwardRef((props, ref) => { const { classPrefix } = useConfig(); const { RoundIcon, ChevronUpIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon } = useGlobalIcon({ RoundIcon: TdRoundIcon, @@ -28,17 +29,35 @@ const PaginationMini = forwardRef((props: PaginationMiniProps, ref: React.Ref(props, paginationMiniDefaultProps); const titleConfig = useMemo(() => { - if (isObject(tips)) return tips; - if (tips === true) return { prev: '上一页', current: '当前', next: '下一页' }; + if (isObject(tips)) { + return tips; + } + if (tips === true) { + return { prev: '上一页', current: '当前', next: '下一页' }; + } return {}; }, [tips]); const disabledConfig = useMemo(() => { - if (isObject(disabled)) return disabled; - if (disabled === true) return { prev: true, current: true, next: true }; + if (isObject(disabled)) { + return disabled; + } + if (disabled === true) { + return { prev: true, current: true, next: true }; + } return { prev: false, current: false, next: false }; }, [disabled]); @@ -89,6 +108,5 @@ const PaginationMini = forwardRef((props: PaginationMiniProps, ref: React.Ref