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

123
Visualizações
how to add array to an object as property?, like object of more than 1 property and one of the property is array

enter image description here IMAGE 1

enter image description here IMAGE 2

enter image description here IMAGE 3

so initially in image 1 i have this function dispatch, when it gets called it passes two argument "type" and "item".

Now the problem is, in image 2 i need to return the item to state object and store it in that state and every time that dispatch function gets called new values of item should be added to state but but......the state object is not retaining the item value, it is removing the previous value and passing the new value so i am receiving only the last value.

I need to map that item property later and for that i need it to be an array, so it should be like:

const state = {
count: 1,
item: [product1, product2, product3, ......]
}

Note: product is an object

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It should be something like

return {
  ...state,
  count : state.count + 1,
  item : [...state.item, action.item]
}
about 4 years ago · Santiago Trujillo Relatório
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