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

133
Views
Persist state when user presses button

I'm new to react and am making a gallery of images, with the functionality to save/bookmark certain images (pressing a bookmark next to the respective image). There is a button to "View saved images" at the top, which will show the user just saved images. Upon pressing the button again (which becomes "View All Images"), the user can see all images again.

The way I am rendering the gallery is as follows:

{images.map((image, index) =< {
            if (viewSaved && savedImages.index(image) > -1) {
                     return <Image data={image}/>
             }
            if (!viewSaved) {
                     return <Image data={image} />
           }
         }
}                    

The issue here is that when the user is viewing saved images, and then unsaves an image, it disappears because it gets removed from savedImages immediately. How do I persist this state so that saved images don't disappear when you unsave them, while viewing saved images?

My thought process is I need to freeze the state, and then only update that state when the viewSaved button is clicked, but I'm unsure how to go about doing this the right way.

about 4 years ago · Santiago Gelvez
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!