I have a reduce, so the ACTION_ADD_PRODUCTS call product list, the ACTION_ADD_TO_CARD action call adding products in the card and ACTION_REMOVE_FROM_CARD should remove from the card, but I can't understand how to make ACTION_REMOVE_FROM_CARD return, that when I click on one of the remove buttons, the item should be removed from the card array;
const initialState = {
products: [],
card: []
}
export const rootReducer = (state = initialState, action) => {
switch (action.type) {
case ACTION_ADD_PRODUCTS:
return {...state,
products: action.payload}
case ACTION_ADD_TO_CARD:
return {
...state,
card: [...state.card, action.payload]
}
case ACTION_REMOVE_FROM_CARD:
return {
card: [...state.card, action.payload]
}
default:
}
return state;
};