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

199
Views
data loss in local Storage on page reload

enter image description hereI am trying to save my data to local Storage and it succeeds, but when reloading the page it disappears, is there any way to handle it, I am new and need help, thanks a lot

Code Sample

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

0

Base on your code, you lose your storage since the effect will override values and set it empty, and this happens since you do not validate if cart items are empty or not.

In react hook in your example, the first call will be with init value (maybe it's null), and if it's not fetching data again so that it will be removed.

Try to add this to your effect (as an example):

if(cartsItem.length > 0){
  // set local storage.
}

Another thing, you need to make sure if this is not fully coded if there's any place was remove local storage and its important.

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!