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..d20993bf 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, + 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, + currentProp, + ); + + const current = Math.max( + 1, + Math.min(internalCurrent, calculatePage(undefined, pageSize, total)), + ); const [internalInputVal, setInternalInputVal] = React.useState(current);