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

138
Vistas
How to animate React preloader disappearance?

I've faced a problem with removing preloader from the page smoothly. At first I had a thought to change content variable and render it on the page but the preloader disappeared too fast. I have created class .closed there is opacity: 0; but it doesn't work Thanks for help!

const App = () => {
    const [loading, setLoading] = useState(true);

    useEffect(() => {
        setTimeout(() => {
            setLoading(false);
        }, 5000);
    });

    const content = loading ? <Preloader/> : <h1>Hello world!</h1>

    return (
        <div className='app'>
            {content}
        </div>
    );
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In this case try adding an empty dep array to your useEffect and cleaning it up after the your done with a return statement. Try something like this.

useEffect(() => {
  const timer = setTimeout(() => {
    setLoading(false)
  }, 5000);
  return () => clearTimeout(timer);
}, []);

This way the the setTimeout is only called once on first render.

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