Fix pagination resetting to page zero with manualPagination (#1369)

* Fix pagination resetting to page zero with manualPagination

To be honest I'm not sure what this useLayoutEffect is there to do.
It has no visible effect if you don't use manualPagination, and if you
do it, simply jumps you back to the first page, defeating the point of
you having control of the pagination.

* Conditionally reset page on data change

Rather disable the whole page reset when filters, groupBy or sortBy
change, just because I wanted to disable the page reset on data change,
make that bit be conditional.

With that in mind, usePagination now accepts a
disablePageResetOnDataChange parameter.
This commit is contained in:
ggascoigne
2019-07-01 09:36:42 -06:00
committed by Tanner Linsley
parent addf28a011
commit ead3599378
+4 -2
View File
@@ -23,6 +23,7 @@ export const usePagination = props => {
const {
rows,
manualPagination,
disablePageResetOnDataChange,
debug,
state: [
{
@@ -37,6 +38,7 @@ export const usePagination = props => {
]
} = props
const rowDep = disablePageResetOnDataChange ? null : rows
useLayoutEffect(() => {
setState(
old => ({
@@ -45,8 +47,8 @@ export const usePagination = props => {
}),
actions.pageChange
)
}, [rows, filters, groupBy, sortBy])
}, [setState, rowDep, filters, groupBy, sortBy])
const { pages, pageCount } = useMemo(() => {
if (manualPagination) {
return {