i try to update the some data into store. When i try to use props.setReducerData(newData) in code, it is keeps updating the page and page keep loading and shwoing the message
” Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn’t have a dependency array, or one of the dependencies changes on every render”
useEffect(() => {
let DataArray1 = props.DataArray1;
let DataArray2 = props.DataArray2;
let newData;
if(DataArray1 && DataArray1 ?.length > 0 &&
DataArray2 && DataArray2?.length > 0)
{
newData = DataArray1 && DataArray1.map(item => {
const match = DataArray2.some(
DataObj => item.id === DataObj.id
);
return {
...item,
amount: match ? 0 : 100
};
});
props.setReducerData(newData); // update the new data into store
} else {
newData = DataArray1 && DataArray1.map(item => {
return {
...item,
amount: 100
};
});
props.setReducerData(newData); // update the new data into store
}
},[
props.DataArray1,
props.DataArray2
]);