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

193
Views
How can i render specific object prop on page after selected opinion fire onChange() method

I will simplify as code is bit huge.

My pizzas has arrays for size and price. When user select size i want to update price, problem is that pizzas are mapping from cart... brainstorming for half a day and stuck. please help.

{cart.products.map((product,index) => (
   
          <Product key={index}>
            <ProductDetail>
              <Image src={product?.img} />
                  <Details>
                    <ProductName>
                      <b>Pizza:</b> {product?.name}
                    </ProductName>
                    
                  <PizzaSelect  onChange={handleChange} > //do i need value here?
                    
                      {product.size.map((size,i)=>(
                      <FilterSizeOption  key={i} value={product.price[i]} >{size}</FilterSizeOption>))}
                  </PizzaSelect>


                  </Details>        
             </ProductDetail>      
              <PriceDetail>
                  <ProductPrice>
                   €{product.price[0]} //problem
                  </ProductPrice>
                  <RemoveItemButton onClick={()=>emptyCartByProduct(product)}>delete</RemoveItemButton>
              </PriceDetail>
             
          </Product> ))}

my handleChange

const handleChange = (e) =>{

 console.log(e.target.value) 
 
}

i did get price for specific pizza.

in database i have size:[small,normal,big] also for price price:[2,3,4]

on first render all is fine. Maybe to create some map?

  • used styled-components
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

for now i have this solution:

 const handleChange = (e) =>{
const target=e.target.value.split(",")

 document.getElementById(target[1]).innerText = '€'+target[0]
}

and then in render:

{cart.products.map((product,prodi) => (
   
          <Product key={prodi}>
            <ProductDetail>
              <Image src={product?.img} />
                  <Details>
                    <ProductName>
                      <b>Pizza:</b> {product?.name}
                    </ProductName>
                    
                  <FilterSize  onChange={handleChange} >
                    
                      {product.size.map((size,i)=>(
                      <FilterSizeOption  key={i} value={[product.price[i],product._id]} >{size}</FilterSizeOption>))}
                  </FilterSize>


                  </Details>        
             </ProductDetail>      
              <PriceDetail>
                  <ProductPrice id={product._id} >
                   €{product.price[0]}
                  </ProductPrice>
                  <RemoveItemButton onClick={()=>emptyCartByProduct(product)}>delete</RemoveItemButton>
              </PriceDetail>
             
          </Product> ))}`

can someone provide better solution?

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!