From ead3599378ae09e8c676c11f2ed36832e6cd2f66 Mon Sep 17 00:00:00 2001 From: ggascoigne Date: Mon, 1 Jul 2019 08:36:42 -0700 Subject: [PATCH] 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. --- src/hooks/usePagination.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hooks/usePagination.js b/src/hooks/usePagination.js index ee1904e..5e4a438 100755 --- a/src/hooks/usePagination.js +++ b/src/hooks/usePagination.js @@ -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 {