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

146
Vistas
Why do useEffect and useLayoutEffect show same value?

As I understand it, React executes useLayoutEffect before printing DOM in browser, and useEffect executes after it. For example consider this component:

const App = () => {
  useLayoutEffect(() => {
    console.log(document.body.scrollHeight); // shows 1024
  }, [])

  useEffect(() => {
    console.log(document.body.scrollHeight); // shows 1024
  }, [])

  return (
    <div style={{ height: 1024 }}></div>
  )
}

I expected, it show 0 for useLayoutEffect and 1024 for useEffect, but both show 1024

I thought <div style={{ height: 1024 }}></div> print after useLayoutEffect but apparently it's not correct...???

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

0

Both useEffect and useLayoutEffect run after the initial render, so they will print the same output.

You might have missed the actual purpose of useLayoutEffect in this example, read more about it here

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