【发布时间】:2018-11-27 06:08:06
【问题描述】:
CartReducer.js
export default function cartReducer(state = {cart: [],qty:1 }, action) {
switch (action.type) {
case ADD_TO_CART:
if (state.cart.indexOf(action.product) !== -1) {
return state // i want add quantity with increment (qty++)
}
return { cart:[...state.cart, action.product] } // send qty with cart
case REMOVE_FROM_CART:
return {
cart: state.cart.filter(id => id !== action.product_id)
}
default:
}
retrun state;
}
我想通过产品项目传递数量,如果多次单击同一项目 (AddToCart) 然后增加数量 (qty++)
请帮帮我...
【问题讨论】:
标签: reactjs redux shopping-cart reducers