In the Official React docs, for useLayoutEffect, it is mentioned: The signature is identical to useEffect, but it fires synchronously after all DOM mutations. Use this to read layout from the DOM and synchronously re-render. Updates scheduled inside useLayoutEffect will be flushed synchronously, before the browser has a chance to paint.
Also, in useLayoutEffect we are able to read the updated dimensions before the browser actually repaints.
How does react do that ?