export const initialState = {
basket: [],
};
// reducer takes care about adding and removing items from the basket
// selector
export const getBasketTotal = (basket) =>
basket?.reduce((amount, item) => item.price + amount, 0);
// the above code helps us tally the total amount of products
const reducer = (state, action) => {
switch (action.type) {
case "ADD TO BASKET":
return {
...state,
basket: [...state.basket, action.items],
};
// the above code helps us to push items to the basket with current elemnts in the basket
default:
return state;
}
};
export default reducer;
它显示的错误在 export const getBasketTotal 中,它显示的错误是匿名函数