doc: add REMOVE_FROM_BASKET case
This commit is contained in:
@@ -13,6 +13,25 @@ const reducer = (state, action) => {
|
||||
basket: [...state.basket, action.item],
|
||||
};
|
||||
|
||||
case "REMOVE_FROM_BAKSET":
|
||||
const index = state.basket.findIndex(
|
||||
(basketItem) => basketItem.id === action.id
|
||||
);
|
||||
let newBasket = [...state.basket];
|
||||
|
||||
if (index >= 0) {
|
||||
newBasket.splice(index, 1);
|
||||
} else {
|
||||
alert(
|
||||
`Can't remove product (id: ${action.id}) as is not in the basket!`
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
basket: newBasket,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user