Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!