Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"prepare": "husky"
},
"dependencies": {
"@rc-component/util": "^1.2.0",
"@rc-component/util": "^1.3.0",
"classnames": "^2.3.2"
},
"devDependencies": {
Expand Down
25 changes: 14 additions & 11 deletions src/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -75,17 +75,20 @@ const Pagination: React.FC<PaginationProps> = (props) => {

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

const [pageSize, setPageSize] = useMergedState<number>(10, {
value: pageSizeProp,
defaultValue: defaultPageSize,
});
const [pageSize, setPageSize] = useControlledState<number>(
defaultPageSize,
pageSizeProp,
);

const [current, setCurrent] = useMergedState<number>(1, {
value: currentProp,
defaultValue: defaultCurrent,
postState: (c) =>
Math.max(1, Math.min(c, calculatePage(undefined, pageSize, total))),
});
const [internalCurrent, setCurrent] = useControlledState<number>(
defaultCurrent,
currentProp,
);

const current = Math.max(
1,
Math.min(internalCurrent, calculatePage(undefined, pageSize, total)),
);

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

Expand Down