I have a state called this.state.devices
which is an array of device
objects.
Say I have a function
updateSomething: functi
For some reason above answers didn't work for me. After many trials the below did:
if (index !== -1) {
let devices = this.state.devices
let updatedDevice = {//some device}
let updatedDevices = update(devices, {[index]: {$set: updatedDevice}})
this.setState({devices: updatedDevices})
}
And I imported update
from immutability-helper
based on the note from: https://reactjs.org/docs/update.html