Hi Adam,
in Chapter 5 inside the CartReducer you have this:
let existing = newStore.cart.find(item => item.product.id === p.id);
if (existing) {
existing.quantity += q;
} else {
newStore.cart = [...newStore.cart, action.payload];
}
The problem is: If the item already exists in the cart, you change the quantity of the existing item. But: This changes storeData, because existing is inside storeData AND inside newStore. So this makes the function unpure, i.e. it is not what you want as a Reducer.
Hi Adam,
in Chapter 5 inside the CartReducer you have this:
The problem is: If the item already exists in the cart, you change the quantity of the existing item. But: This changes storeData, because existing is inside storeData AND inside newStore. So this makes the function unpure, i.e. it is not what you want as a Reducer.