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

177
Vistas
Can I update whole draft object in immerjs

I want to ask if then is a way to update the whole object in immerjs

For example I want to set my redux state to the output of this function

Sample state

 {
  "1":{
       // properties
     },
   "2":{
     // properties
     }
 }

In the Code below mainly, there are 3 function

ObjectPush: what it does is basically shift all properties down by one(eg 1 becomes 2)from the index(param)

ObjectRemove: Remove particular index and change indexes

deleteStrip:Reducer


const ObjectPush = (obj, index) => {
  return produce(obj, (state) => {
    const keys = Object.keys(state)
      .filter((v) => v !== 'misc')
      .map(Number);

    const draft = Object.assign({}, state);

    keys.forEach((key) => {
      if (key >= index) {
        state[key + 1] = draft[key];
      }
    });

    delete state[index];
  });
};
export const ObjectRemove = (obj, index) => {
  const state = {};
  const updatedState = { ...ObjectPush(obj, index)
  };
  const keys = Object.keys(updatedState)
    .filter((v) => v !== 'misc')
    .map(Number);
  const temp = Object.assign({}, obj);
  keys.map((key) => {
    if (temp[key]) {
      if (key > index) {
        state[key - 1] = temp[key];
      } else {
        state[key] = temp[key];
      }
    }
  });
  return state;
};
 // inside immer produce
deleteStrip: (state, action) => { 
    const { index } = action.payload;
    state = ObjectRemove(state, index);
}
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