Skip to content

Commit c329194

Browse files
author
Fabian Kretzer
committed
use previous state as base for new state
1 parent ede9936 commit c329194

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

lib/FilterHandler.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,18 @@ const withFilterHandler = ComponentToWrap => {
8080

8181
updateFilterConfig(filterFunction, filterComponent, columnName){
8282
if (columnName !== undefined){
83-
let newState = {};
84-
if (filterFunction !== undefined){
85-
newState.filterFunctions = Object.assign({}, this.state.filterFunctions);
86-
newState.filterFunctions[columnName] = filterFunction;
87-
}
88-
if (filterComponent !== undefined){
89-
newState.filterComponents = Object.assign({}, this.state.filterComponents);
90-
newState.filterComponents[columnName] = filterComponent;
91-
}
92-
this.setState(newState);
83+
this.setState((prevState) => {
84+
let newState = {};
85+
if (filterFunction !== undefined){
86+
newState.filterFunctions = Object.assign({}, prevState.filterFunctions);
87+
newState.filterFunctions[columnName] = filterFunction;
88+
}
89+
if (filterComponent !== undefined){
90+
newState.filterComponents = Object.assign({}, prevState.filterComponents);
91+
newState.filterComponents[columnName] = filterComponent;
92+
}
93+
return newState;
94+
});
9395

9496
} else {
9597
let newState = {};

0 commit comments

Comments
 (0)