I have the below code where I am trying to update setState with few properties modified in array of objects
onClick(index) {
let tmp = this.state.daysOfWeek;
tmp[index].active = !tmp[index].active;
if (tmp[index].active === true) {
tmp[index].className = "selectedDay";
} else {
tmp[index].className = "remSelectedDay";
}
this.setState({ daysOfWeek: [...this.state.daysOfWeek, tmp]})
}
Here tmp is modified array of objects. If I use spread operator then the arry of objects are concatinated wiht tmp.
How could I update the current state with array of objects ?
mapand then return updated array.