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

110
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
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