Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
Why can't a getElementById method find an element when imported inside functional component?

I want to use this cool scroll effect in one of my pages.The functional component has the same exact HTML as in the codepen. The script is in a separate file that is imported inside the component file. The problem is this line doesn't work

var well = document.getElementById('well');

I tried to import the JS-file into a variable and the call it in a useEffect hook just to make sure that hte script is run after the DOM is rendered. But it still doesn't work. What do I do to make the script work in my component?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Did you try importing the script like this ?

useEffect(() => {
    const script = document.createElement('script');
    script.src = "source of the js file";
    script.async = false;
    document.body.appendChild(script);
    return () => {
        document.body.removeChild(script);
      }
  }, []);
about 4 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda