I want to increment the object inside the array students of array subjects. And the state is as given below :
state = {
students: [{
name: "",
address: "",
class: "",
subjects: [{ subjectName: "", duration: "" }],
},
],
};
I write the Handle increment for subjects as below:
handleIncrement() {
this.state.students.map((student) => {
this.setState({
student: [...student.subjects, { subjectName: "", duration: "" }],
});
});
console.log(this.state);
}
Button On Click to Increment as below:
<button
type="button"
className="btn btn-primary"
style={myStyle.btnCircle}
onClick={this.handleIncrement}>
<i className="fa fa-plus"></i>
</button>
Problem is I cannot increment the Object inside the subjects array. Please Can anyone help me to solve my problem on the above state format...Please do not suggest me to change my state, Data format. I'm using React js..