I created a basket application with this reducer in reactions / redux:
const initialState = { items: [], cartOpen: false, total: 0 } const Cart = (state = initialState, action) => { switch (action.type) { case 'ADD_TO_CART': let newstate = [...state, action.payload]; var newTotal = 0; newstate.forEach(it => { newTotal += it.item.price; }); newstate.total = newTotal; newstate.cartOpen =true return newstate; case 'TOGGLE_CART': debugger; return !state.cartOpen; default: return state } } export default Cart;
I am trying to set the state for a recycle bin i.e. open, but when I check the logs, the cart property is updated, and not the cartOpen property?
source share