From f370497eaf0ddd5d364a5b997eeca67c8e262c8e Mon Sep 17 00:00:00 2001 From: zhf <877044034@qq.com> Date: Fri, 24 Jul 2020 17:27:42 +0800 Subject: [PATCH 1/2] Update Pagination.jsx fix: bugfix when props: { pageSize: undefined; current: undefined } constructor function thorw an error --- src/Pagination.jsx | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/Pagination.jsx b/src/Pagination.jsx index 64de2d43..170430bc 100644 --- a/src/Pagination.jsx +++ b/src/Pagination.jsx @@ -20,7 +20,7 @@ function defaultItemRender(page, type, element) { } function calculatePage(p, state, props) { - const pageSize = typeof p === 'undefined' ? state.pageSize : p; + const pageSize = typeof p === 'undefined' ? state?.pageSize ?? Pagination.defaultProps.defaultPageSize : p; return Math.floor((props.total - 1) / pageSize) + 1; } @@ -57,19 +57,9 @@ class Pagination extends React.Component { 'Warning: You provided a `current` prop to a Pagination component without an `onChange` handler. This will render a read-only component.', ); } - - let current = props.defaultCurrent; - if ('current' in props) { - // eslint-disable-next-line prefer-destructuring - current = props.current; - } - - let pageSize = props.defaultPageSize; - if ('pageSize' in props) { - // eslint-disable-next-line prefer-destructuring - pageSize = props.pageSize; - } - + + const pageSize = props?.pageSize ?? props.defaultPageSize; + let current = props?.current ?? props.defaultCurrent; current = Math.min(current, calculatePage(pageSize, undefined, props)); this.state = { From c727b3616febc566695bc74aae4499fd44604bca Mon Sep 17 00:00:00 2001 From: zhf <877044034@qq.com> Date: Fri, 24 Jul 2020 17:52:57 +0800 Subject: [PATCH 2/2] Update Pagination.jsx --- src/Pagination.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pagination.jsx b/src/Pagination.jsx index 170430bc..f6e8a183 100644 --- a/src/Pagination.jsx +++ b/src/Pagination.jsx @@ -20,7 +20,7 @@ function defaultItemRender(page, type, element) { } function calculatePage(p, state, props) { - const pageSize = typeof p === 'undefined' ? state?.pageSize ?? Pagination.defaultProps.defaultPageSize : p; + const pageSize = typeof p === 'undefined' ? state?.pageSize ?? 10 : p; return Math.floor((props.total - 1) / pageSize) + 1; }