I'm trying to setState
but I can't figure out how I can destructure the rest of object which has a dynamic property name. In this example id
is a dynamic value for each input in my forms.
After computing the state it looks like this:
{
"inputConfig": {
"5d4d684cadf8750f7077c739": {
"0": "5d4d684cadf8750f7077c739",
"isEmpty": true
},
"5d4d684cadf8750f7077c73c": {
"time": "2019-08-10T12:33:42.439Z",
"units": "f",
"defaultValue": 6,
"name": "Temp",
"isEmpty": true
}
}
}
the dynamic id hols an object with input configuration:
"5d4d684cadf8750f7077c73c": {
"time": "2019-08-10T12:33:42.439Z",
"units": "f",
"defaultValue": 6,
"name": "Temp",
"isEmpty": true
}
This is the code I have tried so far:
this.setState(prevState => ({
...prevState,
inputConfig: {
...inputConfig,
[id]: {
...[id], // gives me {0: "5d4d684cadf8750f7077c739"} instead of the object it holds
}
}}),() =>{
console.log(this.state.inputConfig)
})
I would like to desctructure the object that this id
holds. Is there a way to do it?
I appreciate any advice on this.