Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

220
Vistas
React: can't add an array of objects to the product

I'm trying to add the selected attributes(radio buttons) to the product.ps:// when im not using this.setState in the handleChange function , this almost works, except for the fact that instead of getting an array of multiple objects with selected attributes, I get an array of single object with multiple keys/values.

render() {
    
    let product = this.state.currentProduct;
    let selectedAttributes = [];
    let testobj = {};

 let handleChange = (evt,attribute) => {
      let test = Object.assign({}, product);
      testobj[attribute] = evt.target.value;
      selectedAttributes.push(testobj);
      let noDuplicates = [...new Set(selectedAttributes)];
      test.selectedAttributes = noDuplicates;
      this.setState((state) => ({
        currentProduct: test,
      })) 
    }

return (
      <>
                <ul className={`attributesList ${attribute.id}`} key={attribute.id}>
                  {product.attributes[i].items.map((item) => {
                    return (  
                      <li>
                        <input className={attribute.id} onChange={(evt) => handleChange(evt,attribute.id)} type="radio" id={`attribute ${attribute.id} ${item.id}`} name={`attributesList ${attribute.id}`} value={item.displayValue}/> 
                        <label className={`attribute ${item.id}`} style={{backgroundColor: item.value}} htmlFor={`attribute ${attribute.id} ${item.id}`}>{item.displayValue}</label>
                      </li>
                    )
                  })}
                  </ul>
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda