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

147
Visualizações
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 Respostas
Responde à pergunta

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 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