I'm trying to follow the instructions found in Cleaner/shorter way to update nested state in Redux? [the accepted answer]
The thing is in my particular case, i have a layer that really depends on which model the user has selected up to that point. My structure:
Now in my reducer, i've tried (just want to change the favorite leaf to true):
let newStateForFavorites = {...state, models: {
...state.models,
62416: {
...state.models.62416,
details: {
...state.models.62416.details,
favorited: true
}
}
}};
Javascript complains. If i try to extract it to a var:
const currentModelToFav = action.payload.model_id;
let newStateForFavorites = {...state, models: {
...state.models,
currentModelToFav: {
...state.models.currentModelToFav,
details: {
...state.models.currentModelToFav.details,
favorited: true
}
}
}};
Javascript does not associate the const. And it errors out -currentModelToFav is undefined-
Ideas of what i'm doing wrong? Thanks!