I have a react ecommerce app and i'm trying to add items to my cart component. On a product container i can change the state of a product to "addedToCart" in order to add that product to the cart. My issue is the state is only updating when the cart file changes. I assume the satte desn't get updated immediately by design and is only updating when the cart component changes. I need it to apply the state changes immediately in real time.
Cart.JS
function addToCart() {
products.map((prod) => {
return (prod.id === props.prod.id)?(props.prod.addcart = true):""
})
}
<i className="fas fa-shopping-cart addtocart" onClick={addToCart}></i>