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

108
Views
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 answers
Answer question

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 Report

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 Report
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!