{all_product.map((e)=>{
if(cartItems[e.id]>0){
return(
<div>
<div className="cartitems-format">
<img src={e.image} alt="" className='carticon-product-icon'/>
<p>{e.name}</p>
<p>${e.new_price}</p>
<button className='cartitems-quantity'>{cartItems[e.id]}</button>
<p>{e.new_price*cartItems[e.id]}</p>
<img src={remove_icon} onClick={()=>{removeFromCart()}} alt="" />
</div>
</div>
)
}
})}
In the above it is showing the warning message and showing error in the webpage
2
Answers
The issue here is that when the if condition does not evaluate to true, your arrow function does not indeed return anything. Try to return something in an else case
Array.map
expects to execute on each item of the array. From your code we can deduce execution on each item is conditional i.e based on the cart’s content. A better approach would be to useArray.reduce
.