我生成一个数组
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;
}
}