I'm trying to add/push a javascript object (let's call this 'session') to this.state.sessions.
I've tried this two ways:
1) Concat'ing the new session
this.setState({sessions: this.state.sessions.concat(session)});
2) Using React's immutability helpers
var newState = React.addons.update(this.state, {
sessions : {
$push : [session]
}
});
this.setState(newState);
While the shallow data (e.g. sessions[i].location) is added correctly, the problem is that all prior session's scope is now set to the new session.scope. In the picture link below you can see that the first session's scope values (sessions[0].scope) were overwritten by the second session's scope values (sessions[1].scope). How do I ensure that when I add a new session, prior session's values aren't affected?