Skip to content

Commit

Permalink
fix: onFilter function to use functional updates for improved state m…
Browse files Browse the repository at this point in the history
…anagement (#7486)
  • Loading branch information
KumJungMin authored Dec 7, 2024
1 parent 682aacf commit adfe904
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions components/lib/treetable/TreeTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,27 +494,30 @@ export const TreeTable = React.forwardRef((inProps, ref) => {
};

const onFilter = (event) => {
let filters = getFilters();
let newFilters = filters ? { ...filters } : {};
setFiltersState((prevFilters) => {
const filters = props.onFilter ? props.filters : prevFilters;
const newFilters = filters ? { ...filters } : {};

if (!isFilterBlank(event.value)) {
newFilters[event.field] = { value: event.value, matchMode: event.matchMode };
} else if (newFilters[event.field]) {
delete newFilters[event.field];
}

if (!isFilterBlank(event.value)) {
newFilters[event.field] = { value: event.value, matchMode: event.matchMode };
} else if (newFilters[event.field]) {
delete newFilters[event.field];
}
if (props.onFilter) {
props.onFilter({
filters: newFilters
});
} else {
setFirstState(0);
}

if (props.onFilter) {
props.onFilter({
filters: newFilters
});
} else {
setFirstState(0);
setFiltersState(newFilters);
}
if (props.onValueChange) {
props.onValueChange(processedData({ filters: newFilters }));
}

if (props.onValueChange) {
props.onValueChange(processedData({ filters: newFilters }));
}
return newFilters;
});
};

const cloneFilters = (filters) => {
Expand Down

0 comments on commit adfe904

Please sign in to comment.