Home
← All questions

useLayoutEffect vs useEffect in React

MediumPremiumReact

Asked at Meta · Google · Stripe

React interview practice: When to use layout effects for DOM measurement and avoiding visual flicker.

Answer

Both run after render, but at different times:

useEffectuseLayoutEffect
TimingAfter paint (async, non-blocking)After DOM update, before browser paint
Blocks paintNoYes — use sparingly
Use forData fetch, subscriptions, loggingDOM measurement, sync layout, tooltip positioning

Rule of thumb: start with useEffect; switch to useLayoutEffect only when users see a flash of wrong layout.

Premium question

Unlock the full model answer with Mentoxis Premium.

Unlock with Premium