Submitted over 1 year ago
🟠E-commerce product page | React | Mobile-first | Interactive🟠
#react#animation
@JustANipple
Design comparison
SolutionDesign
Solution retrospective
Hi everyone! i made it through this challenge!
The hardest part was to manage states for every component and passing everything to the "add to cart" button to fill the cart list
Hope you will like it!
I would like to get any tip on how to improve my solution!
Community feedback
- @fazzaamiarsoPosted over 1 year ago
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 helpful0@JustANipplePosted over 1 year agoHi @fazzaamiarso Thank you for the tip, I'll update it as soon as possible This helped a lot to improve the solution
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord