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

179
Visualizações
React grid layout - Local storage with add/remove widgets

I have been trying to get react grid layout setup with my project and have been unable to merge two of the examples. Local storage and add/remove widgets

I figured I needed to also store items in LS and have been trying to get it working but with no luck. Currently, items are being stored, and layout is empty (not sure why), but the items are reset on refresh. I'm pretty sure it's because of the .map in state, but I am unsure how I can fix this.

If anything can help me I would be grateful as I have been stuck on this for awhile.

I have made a sandbox for ease of help

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think this has to do with the fact that the first render of the ResponsiveReactGridLayout component counts as an onChange call. Therefore, it will call saveToLS() with an empty array of items. You should include a useEffect which will get the layout stored in localStorage upon page load. Then store the retrieved layout in a useState and pass this to the ResponsiveReactGridLayout component. After that you could set a flag that allows the ResponsiveReactGridLayout to update and save the layout to local storage, but this is optional.

Also, I would highly recommend changing your code from class based to functional code. Class based coding in React is mostly outdated and only used in specific use cases. Functional programming would future proof your code.

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