From 2f3ffdc97602c9a0a10207d19e46962c3807e3a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AC=A2?= Date: Fri, 12 Sep 2025 11:18:50 +0800 Subject: [PATCH 1/3] refactor: Upgrade utils and replace useMergedState --- package.json | 2 +- src/Pagination.tsx | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 93528fb5..6874deba 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "prepare": "husky" }, "dependencies": { - "@rc-component/util": "^1.2.0", + "@rc-component/util": "^1.3.0", "classnames": "^2.3.2" }, "devDependencies": { diff --git a/src/Pagination.tsx b/src/Pagination.tsx index 77b7d785..e243215a 100644 --- a/src/Pagination.tsx +++ b/src/Pagination.tsx @@ -1,5 +1,5 @@ import classNames from 'classnames'; -import useMergedState from '@rc-component/util/lib/hooks/useMergedState'; +import useControlledState from '@rc-component/util/lib/hooks/useControlledState'; import KeyCode from '@rc-component/util/lib/KeyCode'; import pickAttrs from '@rc-component/util/lib/pickAttrs'; import warning from '@rc-component/util/lib/warning'; @@ -75,17 +75,20 @@ const Pagination: React.FC = (props) => { const paginationRef = React.useRef(null); - const [pageSize, setPageSize] = useMergedState(10, { - value: pageSizeProp, - defaultValue: defaultPageSize, - }); + const [pageSize, setPageSize] = useControlledState( + defaultPageSize || 10, + pageSizeProp, + ); - const [current, setCurrent] = useMergedState(1, { - value: currentProp, - defaultValue: defaultCurrent, - postState: (c) => - Math.max(1, Math.min(c, calculatePage(undefined, pageSize, total))), - }); + const [internalCurrent, setCurrent] = useControlledState( + defaultCurrent || 1, + currentProp, + ); + + const current = Math.max( + 1, + Math.min(internalCurrent, calculatePage(undefined, pageSize, total)), + ); const [internalInputVal, setInternalInputVal] = React.useState(current); From bdf24bbd0bfcf04752c947726995a84c30183a71 Mon Sep 17 00:00:00 2001 From: EmilyyyLiu <100924403+EmilyyyLiu@users.noreply.github.com> Date: Fri, 12 Sep 2025 14:25:48 +0800 Subject: [PATCH 2/3] Update src/Pagination.tsx Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/Pagination.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pagination.tsx b/src/Pagination.tsx index e243215a..a550e796 100644 --- a/src/Pagination.tsx +++ b/src/Pagination.tsx @@ -81,7 +81,7 @@ const Pagination: React.FC = (props) => { ); const [internalCurrent, setCurrent] = useControlledState( - defaultCurrent || 1, + defaultCurrent, currentProp, ); From 1df56ccfa526b111bdc23b37c40aae16fc6052a6 Mon Sep 17 00:00:00 2001 From: EmilyyyLiu <100924403+EmilyyyLiu@users.noreply.github.com> Date: Fri, 12 Sep 2025 14:26:07 +0800 Subject: [PATCH 3/3] Update src/Pagination.tsx Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/Pagination.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pagination.tsx b/src/Pagination.tsx index a550e796..d20993bf 100644 --- a/src/Pagination.tsx +++ b/src/Pagination.tsx @@ -76,7 +76,7 @@ const Pagination: React.FC = (props) => { const paginationRef = React.useRef(null); const [pageSize, setPageSize] = useControlledState( - defaultPageSize || 10, + defaultPageSize, pageSizeProp, );