I am trying to update the finalShapes state from initialShapes state and I am having a problem that finalShapes is not getting updated. I am making some changes in initalShapes state and then storing that manipulated data in finalShapes. Please tell me what am I doing wrong
this.state.initialShapes.map (sh => {
var data = {};
data.name = sh.name;
data.x1 = sh.x;
data.y1 = sh.y;
data.x2 = sh.x + sh.width;
data.y2 = sh.y + sh.height;
this.setState ({finalShapes : [...this.state.finalShapes, data]});
});
setState
are you trying to update the state on each iteration?this.setState(prevState => { ... })
.