I want to capture the value of my state "GeoJson" at the moment M, so here is what I do:
const prevGeoJson = Object.assign({}, this.state.geoJson);
const geoJson = Object.assign({}, this.state.geoJson);
geoJson.features.push(data);
this.setState(prevState => ({
prevGeoJson: prevGeoJson,
geoJson: geoJson,
currentMarker: data
}));
But then, the value of this.state.prevGeoJson
has the same value than this.state.GeoJson
. I guess it is a normal behaviour from Object.assign, but don't understand why, and what is the solution?