I have a button that should decrease a number. How can I create a condition that stops decreasing when my number is 1 in React?
<Button type="button" size="small" onClick={() =>
handleUpdateCartQty(item.id, item.quantity - 1)}>-</Button>
something like that:
if(item.quantity == 1){
<Button type="button" size="small" onClick={() =>
handleUpdateCartQty(item.id, item.quantity)}>-</Button>
}else{
<Button type="button" size="small" onClick={() =>
handleUpdateCartQty(item.id, item.quantity - 1)}>-</Button>
}
Note
item.quantity
holds the value of the number