Please see this question first here. I am using this sample object that everyone has been using.
{
entities: {
plans: {
1: {title: 'A', exercises: [1, 2, 3]},
2: {title: 'B', exercises: [5, 6]}
},
exercises: {
1: {title: 'exe1'},
2: {title: 'exe2'},
3: {title: 'exe3'}
5: {title: 'exe5'}
6: {title: 'exe6'}
}
},
currentPlans: [1, 2]
}
When the user clicks on "Remove Exercise", the message might look something like this:
{type: "REMOVE_EXERCISE", payload: 2}
Do I need to iterate over all plans, and then all exercises within each plan in order to remove this item ? How would this be done in the reducer ?
omit(state.entities.exercises, 2)
. Does this help? – Prostituteplan.exercises
, you can use theArray.filter
function to keep all ids except the one that was removed, something like:plan.exercises.filter(id => id!==2)
– Fervency