So I'm working on a project where I want to have a shopping cart and inside of that shopping cart you can see the product's quantity and change it by clicking the buttons on the side of it. The problem is that the value of the quantity updated but it is not shown in the shopping cart and it doesn't seem to be taking an effect on the price at all. The quantity is being stored as an object and is updated in functions called upon pressing the buttons. Here's the releveant code: Those are my decrease and icnrease functions:
const increaseQuantity=(product)=>{
product.quantity+=1;
}
const decreaseQuantity=(product)=>{
if(product.quantity<=1){
alert('ERROR')
}
if(product.quantity>=1){
product.quantity-=1;
}
}
and that is where I show the price within the map function:
{productsInCart.map(product=>
<div className='productsWrapper'>
<p className='productName'>{product.name}</p>
<img className='productImage' src={product.image}/>
<p className='productPrice'>
<span className='productQuantity'>
<FaArrowLeft className='decreaseQuantity' size={20} onClick={()=>decreaseQuantity(product)}/>
<span className='quantity'>
{product.quantity}
</span>
<FaArrowRight className='increaseQuantity' size={20} onClick={()=>increaseQuantity(product)}/>
</span> Total: ${product.price*product.quantity}</p>
<FaTrash className='removeProduct' size={25} onClick={()=>removeFromCart()}></FaTrash>
<hr></hr>
<span className='calculateTotal'>{totalSumDollars+=product.price}</span>
</div>)
}
And this is where my products are being stored:
const productssList=[
{
name: 'Product 2',
image: MissingImage,
price: 5.50,
quantity: 1,
id: 0
},
{
name: 'Product 1',
image: MissingImage,
price: 3.40,
quantity: 1,
id: 1
},
<span className='quantity'> {product.quantity} </span>when you increase and decrease?