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

88
Views
cómo establecer el estado y actualizar un objeto dentro de una matriz

Necesito tu ayuda por favor :-)

 state = { order: { createdAt: Date.now(), products: [ { leftInStock: "12", productName: "בלה", productPrice: "120", qtyInOrder: 0 } ], totalPrice: 0, miniClient: { id: '', fullName: '' } }, client: null, isClientSelected: true }

y esta es la función que debería realizar la actualización del objeto (es necesario actualizar qtyInOrder).

 setQtyForProduct = (product, name) => { if (name === '+') product.qtyInOrder++ if (name === '-') { if (product.qtyInOrder === 1) return else product.qtyInOrder-- } const { products } = this.state.order this.setState({ order: { ...this.state.order, products: [...products, product] } }, () => { this.getOrderPrice() }) }

así paso los valores

 <div className="order-selected-product-list"> {this.state.order.products.map((product, _id) => { return ( <div key={_id} className="order-product"> <div className="order-selected-product-card"> <div>{product.productName}</div> <div>{product.qtyInOrder}</div> </div> <div className="order-products-qty-btns"> <div onClick={() => this.setQtyForProduct(product, "+")}>+</div> <div onClick={() => this.removeProductFromOrder(product)}>הסר</div> <div onClick={() => this.setQtyForProduct(product, "-")}>-</div> </div> </div> ) })} </div>

Obtuve los valores correctos, lo único que no pude hacer es actualizar el

Sé que hay algo mal con mi función setState porque agrega los productos en lugar de actualizar la clave en él

about 4 years ago · Juan Pablo Isaza
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!