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

187
Vistas
React: added product changes it's attributes after I add another product with different attribute while on the same product page

So let's say you are on the product page of a Nike T-shirt, you choose the color and size(eg:black and S) and add it to cart. Now the cart contains 1 Nike T-SHIRT with selectedAttributes: color: black, size: s. Now, while on the same T-shirt page, you choose color white and size M, the previous added T-shirt's attributes change from (color:black into color: white, and form size:s into size:M) and now you have in cart 2 T-SHIRTS SIZE :M AND COLOR: BLACK. What am I doing wrong?

class PDP extends Component {
      state = {
        currentProduct: this.props.location.state,
        selectState: [],
        testObj: {},
      } 
    render() {
    let product = this.state.currentProduct;
    let handleChange = (evt,attribute) => {
            const test = Object.assign({}, product);
            this.state.testObj[attribute] = evt.target.value;
            this.state.selectState.push(this.state.testObj);
            let selectedAttributes = [...new Set(this.state.selectState)];
            test.selectedAttributes = selectedAttributes;
            this.setState((state) => ({
              currentProduct: test
            }))
          } 
    
    <button className="addToCart" onClick={() => this.props.data.addProduct(this.state.currentProduct)}>ADD TO CART</button>
    
     addProduct = (product) => {
        this.setState((state) => ({
          cart: state.cart.concat(product),
        }))
       
      } 
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