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

129
Visualizações
Storing data across nextjs pages

I'm building a react app with next and I'd like to store some data to be accessed on another page. I followed this guide on the creating a useLocalStorage hook however I keep getting an error NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.

I have this function:

function useLocalStorage(key, value) {
  const [storedValue, setStoredValue] = useState(() => {
    if(typeof window !== "undefined"){
      const item = window.localStorage.getItem(key)
      return item ? JSON.parse(item) : value;
    }
  })

  const setValue = (value) => {
    useEffect(()=>{
      const valueToStore = value instanceof Function ? value(storedValue) : value
      
      setStoredValue(valueToStore)
      
      if(typeof window !== "undefined"){
        window.localStorage.setItem(key, JSON.stringify(valueToStore))
      }
    },[])
  }

  return [storedValue, setValue]
}

and then

const [data, setData] = useLocalStorage("data", props)

with setData called from a button which goes to the next page

any help/criticism is greatly appreciated and if there is a simpler/better way to do this that would be amazing.

Thanks!

about 4 years ago · Juan Pablo Isaza
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