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

210
Vistas
How to update a specific index of an array when using spread operator

This is a more of a can it ever be done even with a parser like babel or anything type of question which i believe is allowed in SU. All just to make my code cleaner for Reducer and State in general; what I want to do is:

return {
   ...state,
   myObj: {
       ...state.myObj,
      items: [
        ...state.myObj.items,
        [index]: newValue, // do something like this
      ]
   }
}

Anyone know how we can do this cleanly? I dont want to use a slice() or just do newState.myObj.items[index] = newValue as that messy and difficult to read as per other SU answers. Maybe I'm the only one that OCD about clean reducer states, without using a library. Anyone have come across this pattern or how one may achieve it? Id be happy to install a bebel plugin but cant seem to find one.

Thanks

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