Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
there is lag in my react app on a add to card button

I don't know why my react app is lagging after clicking on add to cart button, It takes multiple clicks to add a product into the cart.

following are the app.js file and products.jsx file where the contexts are being consumed The logic is working very well but the only problem is the lag after clicking the add to cart button. Here is the link for codesandbox so that you can get a clear idea about my problem

click here to access codesandbox of my react app

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There is no lag. The problem is that inside the Product.jsx, the onClick is inside the span instead of the button and the span doesn't occupy the whole button. When you click the button (the outer part which the span doesn't reach), no function is called. But on the chance that you click on the inner part, the onClick of the span is called.

tldr; move the onClick from the span to the button.

<button className="product-add-button" onClick={() => handleAddProduct(productItems)}>
  {" "}
  <span>
    {" "}
    <FaShoppingCart
      color="green"
      fontSize="25px"
      className="but-cart"
      />{" "}
    Add to cart
  </span>
</button>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!