Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

🟠E-commerce product page | React | Mobile-first | Interactive🟠

Sam 910

@JustANipple

Desktop design screenshot for the E-commerce product page coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
3intermediate
View challenge

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

@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

0

Sam 910

@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

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join 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