Skip to Content
Full-Stack React Projects - Second Edition
book

Full-Stack React Projects - Second Edition

by Shama Hoque
April 2020
Intermediate to advanced
716 pages
18h 55m
English
Packt Publishing
Content preview from Full-Stack React Projects - Second Edition

Removing items

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Full-Stack React Projects

Full-Stack React Projects

Shama Hoque
React Native - The Practical Guide

React Native - The Practical Guide

Academind by Maximilian Schwarzmüller GmbH

Publisher Resources

ISBN: 9781839215414Supplemental Content