May 2018
Intermediate to advanced
470 pages
13h 54m
English
The remove item option rendered for each item in the cart is a button, which, when clicked, passes the array index of the item to the removeItem method so that it can be removed from the array.
mern-marketplace/client/cart/CartItems.js:
<Button color="primary" onClick={this.removeItem(i)}>x Remove</Button>
The removeItem click handler method uses the removeItem helper method to remove the item from the cart in localStorage, then updates the cartItems in state. This method also checks whether the cart has been emptied, so checkout can be hidden by using the setCheckout function passed as a prop from the Cart component.
mern-marketplace/client/cart/CartItems.js:
removeItem = index => event =>{ let cartItems = cart.removeItem(index) ...Read now
Unlock full access