I have a state:
state = {
obj1: {
name: "",
message: "",
}
}
I have a form:
<form>
<input id={obj1.name} onChange={this.handleChange}/>
<input id={obj1.message} onChange={this.handleChange}/>
</form>
on handleChange:
handleChange(e) {
const {id, value} = e.target
this.setState({[id]:value});
}
Instead of updating the obj1 in the state, it will create a new state variable and obj1 doesn't get updated. [id] : value works on state variables that are not objects. How can I achieve setting a new state in an object through a form change?