Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda