Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda