case 'favoriteRecipes/removeRecipe':
return {
...state,
favoriteRecipes: state.favoriteRecipes.filter(element => element.id !== action.payload.id)
};
case 'favoriteRecipes/removeRecipe':
return {
...state,
favoriteRecipes: [favoriteRecipes.filter(item => item !== action.payload)]
}
the second paste is incorrect, the first paste is correct, i vaguely understand this but… barely.
so the way I look at these reducer cases is we spread an existing copy of state, then after that we list a key in the state object that we want to update
but if you see …state, favoriteRecipes
favoriteRecipes knows were still in the state object somehow, whereas its neccesary to include “state.favoriteRecipes” in the filter statement? why is that?