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

175
Views
Benefit of using OldState / PrevState in React?

I don't understand completely the benefit of using oldState / prevState. In the tutorial the code was changed from this :

  const DeleteClick = (id) => {
    SetMylist(Elems.filter(Elem => id !== Elem.id))
  }

to this :

  const DeleteClick = (id) => {
    SetMylist(OldElems => {
      return OldElems.filter(Elem => id !== Elem.id)
    })
  }

The guy said in the tutorial that if we use oldState / prevState then we get the most recent ( updated ) version of the state variable.

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

0

You will be able to learn what the difference between setState and prevState is and what the benefit of prevState is from https://www.delftstack.com/howto/react/react-setstate-prevstate/#:~:text=setState%20is%20the%20primary%20method,that%20component%2C%20we%20use%20this.

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!