doc: add REMOVE_FROM_BASKET case

This commit is contained in:
Leon Xu
2022-05-05 22:16:07 -07:00
parent 135883ec9c
commit 010d9af9df
+19
View File
@@ -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;
}