• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

220
Vistas
React: TypeError: Cannot read property 'getItem' of null

I'm created a simple React app and added a banner. But I'm getting a lot this error in Sentry from users.

Cannot read properties of null (reading 'getItem');

If someone knows what is a problem tell me please

setTimeout(() => {
  const banner = document.getElementById("banner");

  if (!window.localStorage?.getItem("seen")) {
    const button = document.getElementById("hide");

    if(button){
      button.addEventListener('click', () => {
      window.localStorage?.setItem("seen", 'true');
        banner.style.bottom = "-10vh";
        setTimeout(() => banner.remove(), 2000);
      });

      banner.style.removeProperty("visibility");
      setTimeout(() => banner.style.removeProperty("bottom"), 100);
    }
  } else banner?.remove();
}, 2000);
about 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

That is probably the key: value getItem is empty or undefined in local storage thus you are getting that error, goto local storage on the browser and check your key-value pair in local storage

about 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda