I have a state called this.state.devices
which is an array of device
objects.
Say I have a function
updateSomething: functi
In my opinion with react state, only store things that's really related to "state", such as things turn on, off, but of course there are exceptions.
If I were you I would pull away the array of devices as a variable and set things there, so there is what I might do:
var devices = [];
var MyComponent = React.createClass({
...
updateSomething: function (device) {
var index = devices.map(function(d){
return d.id;
}).indexOf(device.id);
if (index !== -1) {
// do some stuff with device
devices[index] = device;
if(NeedtoRender) {
this.setState({devices:devices});
}
}
}
});