April 2020
Intermediate to advanced
716 pages
18h 55m
English
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 ...