Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda