Skip to content

Commit

Permalink
chore: adjusting state on prop change in an Effect
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanVor committed Feb 11, 2024
1 parent 7a53e94 commit 504d856
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ export const TableColumnSetup = (props: TableColumnSetupProps) => {

const [items, setItems] = React.useState(prepareItems(propsItems));

React.useEffect(() => {
const [prevPropsItems, setPrevPropsItems] = React.useState(propsItems);
if (propsItems !== prevPropsItems) {
setPrevPropsItems(propsItems);

const newItems = prepareItems(propsItems);
setItems(newItems);
}, [propsItems]);
}

const onApply = () => {
const newSettings = items.map<TableSetting>(({id, isSelected}) => ({id, isSelected}));
Expand Down

0 comments on commit 504d856

Please sign in to comment.