Increasing Cart Item count
Import the "increaseItemCount" function from the fingertipps-handshakes package. pass in the cart item you want to it's count increased. here is our implementation of this
import { increaseItemCount } from "fingertipps-handshakes";
const CartPage = () => {
const updateCartCount = (count) => {
console.log(count);
// code to update your ui
};
return (
<div>
{itemsInCart
? itemsInCart.map((item) => (
<div key={item._id}>
<div>
<img src={item.photo[0].picture} alt="" />
</div>
<p>{item.name}</p>
<p>₦{item.price.toLocaleString()}</p>
<p>{item.count.reduce((a, c) => a + c, 0).toLocaleString()}</p>
<button
onClick={() =>
increaseItemCount(item, updateCartCount) & UiUpdate()
}
>
-
</button>
</div>
))
: ""}
</div>
);
};
export default CartPage;
In the code snippet above, we are iterating through an array of objects that we received from the "getCartItems" function. Whenever the user clicks the increase button for an item, that specific item is passed to the "increaseItemCount" function. As a result, the count of that item is automatically increased.