@fazzaamiarso
Posted
Hi Sam! Great job on completing the project!
I have a quick tip for you.
The vote state is excessive because you can derive the Vote
value from the cart's quantity. Here's how
// `cart` is cartItems and `setCart` is setCartItems
const Vote = ({ cart, setCart }) => {
function handlePlusClick() {
// increment the quantity directly
setCart((prevCart) => ({ ...prevCart, quantity: prevCart.quantity + 1 }));
}
function handleMinusClick() {
if (cart.quantity <= 0) return;
// decrement the quantity directly
setCart((prevCart) => ({ ...prevCart, quantity: prevCart.quantity - 1 }));
}
return (
<div className={styles.container_vote}>
<button className={styles.vote_plus} onClick={handleMinusClick}>
<img src="icon-minus.svg" alt="downvote" />
</button>
<p className={styles.vote_score}>{cart.quantity}</p>
<button className={styles.vote_minus} onClick={handlePlusClick}>
<img src="icon-plus.svg" alt="vote" />
</button>
</div>
);
};
I hope it helps you! Cheers!
Marked as helpful
@JustANipple
Posted
Hi @fazzaamiarso Thank you for the tip, I'll update it as soon as possible This helped a lot to improve the solution