I have an array of Objects in state, like so:
this.state = {
week: [
{
en: 'Mon',
morn: false,
night: false,
},
//... the rest of the days...
I can successfully toggle the morn and night Booleans, like so:
this.setState(prevState => {
prevState.week.map(day => {
if (target.includes(day.en)) {
if (target.includes('morn')) {
day.morn = !day.morn;
//^ right here
}
if (target.includes('night')) {
day.night = !day.night;
//^ and here
}
}
return day;
});
});
eslint complains: Assignment to property of function parameter 'day'.
eslintdon't like that you are mutate thedayargument, and he has a point. you should return new object.