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,