April 2020
Intermediate to advanced
716 pages
18h 55m
English
Each item in the cart will have a remove option next to it. This remove item option is a button that, when clicked, passes the array index of the item to the removeItem method so that it can be removed from the array. This button is rendered with the following code.
mern-marketplace/client/cart/CartItems.js:
<Button color="primary" onClick={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 the state. This method also checks whether the cart has been emptied so that checkout can be hidden by using the setCheckout function passed as a prop from the Cart component. The removeItem click handler method ...