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

207
Views
Redux: no se puede actualizar la cantidad del producto que ya está en el carrito, sino que crea el objeto nuevamente

Cuando agrego el producto al carrito y luego agrego otro, entonces si intento agregar el primero nuevamente, no aumenta solo la cantidad sino que crea un nuevo objeto para este producto; Cómo puedo arreglarlo

 switch (action.type) { case actionTypes.ADD_TO_CART: const product = state.products.find((p) => p.id === action.payload.id); const inCart = state.cart.find((item) => item?.product.id === action.payload.id ? true : false ); if (inCart) { let check = false; state.cart.map((item, key) => { if ( item.product.id === action.payload.id && item.setVar === action.payload.setVar ) { state.cart[key].quantity++; check = true; } }); if (!check) { const newItem = { product: product, setVar: action.payload.setVar, quantity: 1, }; state.cart.push(newItem); } } else { const newItem = { product: product, setVar: action.payload.setVar, quantity: 1, }; state.cart.push(newItem); } return { ...state, }; }
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

item.product.id === action.payload.id && JSON.stringify(item.setVar) === JSON.stringify(action.payload.setVar)
          
about 4 years ago · Santiago Gelvez 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!