pass the instance with updated rows (#1714)

This commit is contained in:
Martin Brenner
2019-12-05 09:14:07 -05:00
committed by Tanner Linsley
parent 9829927fab
commit 487abd2119
2 changed files with 39 additions and 18 deletions
+20 -9
View File
@@ -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,
+19 -9
View File
@@ -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,