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

195
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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