From 487abd21193d081096bcee1507689f9e326ee9c8 Mon Sep 17 00:00:00 2001 From: Martin Brenner Date: Thu, 5 Dec 2019 15:14:07 +0100 Subject: [PATCH] pass the instance with updated rows (#1714) --- src/plugin-hooks/useFilters.js | 29 ++++++++++++++++++++--------- src/plugin-hooks/useSortBy.js | 28 +++++++++++++++++++--------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/plugin-hooks/useFilters.js b/src/plugin-hooks/useFilters.js index e271f28..fdb3a8e 100755 --- a/src/plugin-hooks/useFilters.js +++ b/src/plugin-hooks/useFilters.js @@ -132,15 +132,6 @@ function useInstance(instance) { const preFilteredRows = rows const preFilteredFlatRows = flatRows - // Bypass any effects from firing when this changes - const isMountedRef = React.useRef() - safeUseLayoutEffect(() => { - if (isMountedRef.current) { - dispatch({ type: actions.resetFilters }) - } - isMountedRef.current = true - }, [dispatch, ...(getResetFiltersDeps ? getResetFiltersDeps(instance) : [])]) - const setFilter = (columnId, filterValue) => { dispatch({ type: actions.setFilter, columnId, filterValue }) } @@ -289,6 +280,26 @@ function useInstance(instance) { }) }, [filteredRows, filters, flatColumns]) + // Bypass any effects from firing when this changes + const isMountedRef = React.useRef() + safeUseLayoutEffect(() => { + if (isMountedRef.current) { + dispatch({ type: actions.resetFilters }) + } + isMountedRef.current = true + }, [ + dispatch, + ...(getResetFiltersDeps + ? getResetFiltersDeps({ + ...instance, + preFilteredRows, + preFilteredFlatRows, + rows: filteredRows, + flatRows: filteredFlatRows, + }) + : []), + ]) + return { ...instance, setFilter, diff --git a/src/plugin-hooks/useSortBy.js b/src/plugin-hooks/useSortBy.js index cf35e8e..7254ff9 100755 --- a/src/plugin-hooks/useSortBy.js +++ b/src/plugin-hooks/useSortBy.js @@ -177,15 +177,6 @@ function useInstance(instance) { // Add custom hooks hooks.getSortByToggleProps = [] - // Bypass any effects from firing when this changes - const isMountedRef = React.useRef() - safeUseLayoutEffect(() => { - if (isMountedRef.current) { - dispatch({ type: actions.resetSortBy }) - } - isMountedRef.current = true - }, [dispatch, ...(getResetSortByDeps ? getResetSortByDeps(instance) : [])]) - // Updates sorting based on a columnId, desc flag and multi flag const toggleSortBy = (columnId, desc, multi) => { dispatch({ type: actions.toggleSortBy, columnId, desc, multi }) @@ -345,6 +336,25 @@ function useInstance(instance) { userSortTypes, ]) + // Bypass any effects from firing when this changes + const isMountedRef = React.useRef() + safeUseLayoutEffect(() => { + if (isMountedRef.current) { + dispatch({ type: actions.resetSortBy }) + } + isMountedRef.current = true + }, [ + dispatch, + ...(getResetSortByDeps + ? getResetSortByDeps({ + ...instance, + toggleSortBy, + rows: sortedRows, + preSortedRows: rows, + }) + : []), + ]) + return { ...instance, toggleSortBy,