From 504d856c15b082ac14f0be3777b78ce8d92a2737 Mon Sep 17 00:00:00 2001 From: GermanVor Date: Sun, 11 Feb 2024 02:52:25 +0100 Subject: [PATCH] chore: adjusting state on prop change in an Effect --- .../TableColumnSetup/TableColumnSetup.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/Table/hoc/withTableSettings/TableColumnSetup/TableColumnSetup.tsx b/src/components/Table/hoc/withTableSettings/TableColumnSetup/TableColumnSetup.tsx index ecd54b59c1..1b5a21f87d 100644 --- a/src/components/Table/hoc/withTableSettings/TableColumnSetup/TableColumnSetup.tsx +++ b/src/components/Table/hoc/withTableSettings/TableColumnSetup/TableColumnSetup.tsx @@ -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(({id, isSelected}) => ({id, isSelected}));