This is what my initial state looks like:
Fruits: {
34: {
FruitsID: 34,
FruitsList:{apple, pineapple, banana}
}
}
Here, I want to add fruit items such as 'peach' or 'pear' and remove 'apple' and 'banana'. My 'add fruits' reducer returns what I wrote below, but it seems like this is not working because of the id. However, I do need to use id since there will be several fruit lists, not only one. ex: Fruits:{ 23: {...}, 3980: {...}, 129: {...} }
Fruits: {
[action.id]: {
…state.Fruits[action.id],
FruitsID: action.id,
FruitsList: {
...state.Fruits[action.id].FruitsList.push(action.fruit),
},
},
}
I tried reading several related posts, but couldn't find the one that's applicable for my case.
- if I do this(below), then there's a syntax error under action.fruit saying that it expected ','?
Fruits: {
[action.id]: {
…state.Fruits[action.id],
FruitsID: action.id,
FruitsList: {
...state.Fruits[action.id].FruitsList,
action.fruit
},
},
}