(React) Return( ) show first than useLayoutEffect

Viewed 18

 const [test, setTest] = useState('asd')

  useLayoutEffect(() => {
    console.log('useLayoutEffect')
    setTest('111')
  }, [])


  return (
    <>
      {console.log('return=======>')}
      <Button title={test}/>
    </>
  )

What I expected to do

console.log('return=======>') show after console.log('useLayoutEffect')

Currently to do

console.log('useLayoutEffect') show after console.log('return=======>')

I thought useLayoutEffect runs before rendering component but return =====> shows and useLayoutEffect is running...

1 Answers

From the docs

The signature is identical to useEffect, but it fires synchronously after all DOM mutations.

P.S.

Components run line by line, so it wouldn't be possible to run this before the console.log from the body of the component.

Related