Created
October 29, 2019 20:00
-
-
Save Ifmr24/dfb068473c6e657b7cb490262fe47298 to your computer and use it in GitHub Desktop.
LocalStorage Shopping Cart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const addToCartInLocalStorage = product => { | |
if (!localStorage.getItem("cart")) { | |
localStorage.setItem("cart", JSON.stringify([])); | |
} | |
let cartProducts = JSON.parse(localStorage.getItem("cart")); | |
cartProducts.push(product); | |
localStorage.setItem("cart", JSON.stringify(cartProducts)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment