如何从购物车中取出货物?

时间:2019-04-29 09:11:16

标签: redux

我生成一个数组

CartList() {
    return this.props.cartBooks.map((book) => {
      return (
        <CartBook removeToCart={() => this.props.removeToCart(book)} key={book.id} name={book.nameBook} price={book.priceBook} img={book.imgBook} description={book.description} callBack={this.openCloseScreen} close={this.closeScreen}/>
      );
    });
  }

我的异径管(只能去除)

const initialState = {
  addedIds: []
};

export default function (state = initialState.addedIds, action) {
  switch (action.type) {
    case 'ADD_BOOK':
      if (state.indexOf(action.payload) !== -1) {
        return state;
      }
      return [...state, action.payload];
    case 'REMOVE_BOOK':
      if (state.indexOf(action.payload) !== -1) {
        return state;
      }
      return [...state, state.filter((book) => action.payload !== book)];
    default:
      return state;
  }
}

0 个答案:

没有答案