fix: manualPagination does not work with pageCount -1 (#2024)

* fix: manualPagination does not work with pageCount -1

* fix: manualPagination does not work with pageCount -1
This commit is contained in:
Vivek Kumar Bansal 2020-04-01 22:04:20 +05:30 committed by GitHub
parent 0f695e7321
commit e73199a04d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,12 +43,18 @@ function reducer(state, action, previousState, instance) {
}
if (action.type === actions.gotoPage) {
const { pageCount } = instance
const { pageCount, page, rows } = instance
const newPageIndex = functionalUpdate(action.pageIndex, state.pageIndex)
const cannnotPreviousPage = newPageIndex < 0
const cannotNextPage =
pageCount === -1
? page.length < state.pageSize
: newPageIndex > pageCount - 1
if (newPageIndex < 0 || newPageIndex > pageCount - 1) {
if (cannnotPreviousPage || cannotNextPage) {
return state
}
return {
...state,
pageIndex: newPageIndex,
@ -153,7 +159,8 @@ function useInstance(instance) {
])
const canPreviousPage = pageIndex > 0
const canNextPage = pageCount === -1 || pageIndex < pageCount - 1
const canNextPage =
pageCount === -1 ? page.length >= pageSize : pageIndex < pageCount - 1
const gotoPage = React.useCallback(
pageIndex => {