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

127
Views
Difference between ComponentDidUpdate and SetState callback function

I've done some research about an error I got in my react native app

Warning: An update (setState, replaceState, or forceUpdate) was scheduled from inside an update function. Update functions should be pure, with zero side-effects. Consider using componentDidUpdate or a callback..

I've done research but I still can't understand the difference between them. My theoretical idea is to remove an element from an array of objects, but when I use setState with a callback function I get the error. Can anyone point me in the right direction or show me an example of how I can use componentDidUpdate. The code example below works for now but I feel it could be improved on, and I believe that is why I'm getting my error

  Delete_Task = (e) => {
    this.setState(prevState => {
      const tasks = prevState.daily.filter(task => task.ID !== e);
      this.setState({daily: tasks});
    })
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to return the new state object instead of calling another setState inside the outer setState callback

change

this.setState({daily: tasks});

To

return {daily: tasks};
// OR 
return {...prevState, daily:tasks}
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!