I am tring to update a single value in the state, this is my state:
state = {
courses: [
{
id: 1,
courseName: 'lenguage',
courseType: false,
courseHours: 10,
courseGrade: ''
},{
id: 2,
courseName: 'Math',
courseType: true,
courseHours: 20,
courseGrade: ''
},{
id: 3,
courseName: 'Biology',
courseType: false,
courseHours: 30,
courseGrade: ''
}
]
};
I got the value I want to update and the index of the object inside the array but I cant find a way to update the value... This is what I have so far:
updateCourseGrade(courseGrade, id){
const index = this.state.courses.findIndex(course => (
id === course.id
));
const courses = [...this.state.courses];
courses[index].courseGrade = courseGrade;
this.setState({courses});
}
as well I thought tried this block
const course = this.state.courses[index];
this.setState({
courses: [...this.state.courses, course.courseGrade: courseGrade]
})
any help would be amazing tnx!