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

143
Views
How to fix state updating in react?

I am using little state machine for the state management. I have following state

export const todoState = { todoList: []  } 

Now I am calling this using the actions where action is like

export const updateTodoList = (state, payload) => {
    return {
        ...state,
        toDoList: {
            ...state.toDoList,
            ...payload
        }
    }
}

calling this action

 updateToDoList({ id: '1', text:'11', isComplete: 'false })

But still actions does not update the array of toDoList and also it does not take the previous values into consideration .

Can any one help me with the actions updation code ? Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

1) TYPO: todoList instead of toDoList

2) todoList is an array not an object. So spread it into an array.

3) Since you are passing an object so no need to spread it

export const updateTodoList = (state, payload) => {
  return {
    ...state,
    todoList: [
      ...state.todoList,
      payload,        // It will add the payload object into todoList
    ],
  };
};
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!