I want to remove an object of an object in react, what I'm planning to do is get the current state and assign it to a variable, alter that variable, use setState to assigned the altered variable to state. Like this
constructor() {
super()
this.state = {
obj: {
"0": {
something: 123
},
"1": {
another_thing: 'abc'
}
}
}
}
deleteOneObj(index) {
let newObjState = this.state.obj[index]
delete newObjState
}
render() {
return(<h1>hello<br />
<button onClick={()=>this.deleteOneObj(1)}>
delete one obj
</button>
</h1>)
}
But delete newObjState doesn't seem to work.