Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!