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

228
Visualizações
Uncaught TypeError: e is null

I am currently trying to add favorites to an exercise list with the following code

const addFavouriteExercise = (exercise) => {
    const newFavouritesList = [...favourites, exercise];
    setFavourites(newFavouritesList);
    saveToLocalStorage(newFavouritesList);
  };

It works locally, but when I deploy to netlify I get the error Uncaught TypeError: e is null, and it won't add it to local storage.

Any ideas?

saveToLocalStorage

const saveToLocalStorage = (items) => {
  localStorage.setItem("favourites", JSON.stringify(items));
};
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The bug ended up being in a useEffect that I had, where it was attempting to load items from localStorage but set the favourites to an empty object.

Bugs fixed, phew

The new useEffect looks like this:

useEffect(() => {
const exerciseFavourites = JSON.parse(localStorage.getItem("favourites"));
try {
  let length = exerciseFavourites.length;
  if (length > 0) {
    setFavourites(exerciseFavourites);
  }
} catch (e) {
  console.error(e);
}

}, []);

about 4 years ago · Juan Pablo Isaza Relatório

0

You should find where the E is. And try using saveLocalStorage first and then setState to avoid rerender before setting it to localstorege

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