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

111
Visualizações
Mutating Redux Store Array of Objects in ReactJS

My store consists of an array of objects as such:

const INIT_STATE = {
  users:[],
  contacts : []
};

And i am attempting to change mutate the store array like this:

const App = (state = INIT_STATE, action) => {
  switch (action.type) {
    case BLOCK_CONTACT:
      state.contacts.map((contact, index) => {

        if (contact._id === action.payload) {
          state.contacts[index].status = "blocked;
          return {
            ...state
          };
        }
        return {
          ...state
        };
      })
      return {
        ...state
      };
   }
}

But my store value does not change. When i log the state value after the if statement, i get the correct state values but my state is not being updated. I think it might have something to do with my return statement but at this point i have tried different variations with no luck.

Any help will be appreciated.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Also if your app is in the start of the way, you can read this article about jotai state management (Jotai)

about 4 years ago · Juan Pablo Isaza Relatório

0

I figured it out. Incase anyone else that might need help on this, here is the code...

const App = (state = INIT_STATE, action) => {
  switch (action.type) {
    case BLOCK_CONTACT:
      var list = state.contacts.map(contact => {
        var blockList = {
          ...contact
        };

        if (contact._id === action.payload) {
          blockList.status = 1;
        }
        return blockList;
      })
      return {
        ...state,
        contacts: list
      };
   }
}
about 4 years ago · Juan Pablo Isaza 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