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

Empty cart

If the request to the create order API is successful, we will empty the cart in localStorage so that the user can add new items to the cart and place a new order if desired. To empty the cart in browser storage, we will use the emptyCart helper method in cart-helper.js, which is defined as follows.

mern-marketplace/client/cart/cart-helper.js:

emptyCart(cb) {  if(typeof window !== "undefined"){     localStorage.removeItem('cart')     cb()  }}

The emptyCart method removes the cart object from localStorage and updates the state of the view by executing the callback passed to it from the placeOrder method, where it is invoked. With the checkout process completed, we can now redirect the user out of the cart and checkout view, as discussed in ...

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