Skip to content

Commit 2f3ffdc

Browse files
author
刘欢
committed
refactor: Upgrade utils and replace useMergedState
1 parent 5f897f6 commit 2f3ffdc

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"prepare": "husky"
4343
},
4444
"dependencies": {
45-
"@rc-component/util": "^1.2.0",
45+
"@rc-component/util": "^1.3.0",
4646
"classnames": "^2.3.2"
4747
},
4848
"devDependencies": {

src/Pagination.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classNames from 'classnames';
2-
import useMergedState from '@rc-component/util/lib/hooks/useMergedState';
2+
import useControlledState from '@rc-component/util/lib/hooks/useControlledState';
33
import KeyCode from '@rc-component/util/lib/KeyCode';
44
import pickAttrs from '@rc-component/util/lib/pickAttrs';
55
import warning from '@rc-component/util/lib/warning';
@@ -75,17 +75,20 @@ const Pagination: React.FC<PaginationProps> = (props) => {
7575

7676
const paginationRef = React.useRef<HTMLUListElement>(null);
7777

78-
const [pageSize, setPageSize] = useMergedState<number>(10, {
79-
value: pageSizeProp,
80-
defaultValue: defaultPageSize,
81-
});
78+
const [pageSize, setPageSize] = useControlledState<number>(
79+
defaultPageSize || 10,
80+
pageSizeProp,
81+
);
8282

83-
const [current, setCurrent] = useMergedState<number>(1, {
84-
value: currentProp,
85-
defaultValue: defaultCurrent,
86-
postState: (c) =>
87-
Math.max(1, Math.min(c, calculatePage(undefined, pageSize, total))),
88-
});
83+
const [internalCurrent, setCurrent] = useControlledState<number>(
84+
defaultCurrent || 1,
85+
currentProp,
86+
);
87+
88+
const current = Math.max(
89+
1,
90+
Math.min(internalCurrent, calculatePage(undefined, pageSize, total)),
91+
);
8992

9093
const [internalInputVal, setInternalInputVal] = React.useState(current);
9194

0 commit comments

Comments
 (0)