I have a state with nested object in it. I need to setState()
the state value with the onChange
event with every word I write in the input section.
i tried to update directly with this.state.rootProperty.childProperty
but it creates a new state rootProperty.childProperty: "value i wrote"
.
Any ideas on how to setState
those nested state?
Thanks.
this.state = {
taskData: "",
memberData: "",
judul: "",
kode: "",
ketua_team: "",
koordinator: "",
tgl_mulai: "",
tgl_selesai: "",
detail1: {
no: "",
tiket: "",
deskripsi: "",
target: "",
auditor: "",
nil_peg: "",
nil_at: "",
nil_at_at: "",
},
//this is my state, i need to update auditor value with handler
onChangeNest(e) {
this.setState({ [e.target.name]: e.target.value });
}
//and my input props
<input
type="text"
placeholder="auditor"
name="detail1.auditor"
onChange={this.onChangeNest}
></input>