The following diagram always helps me to visualize the flow of hooks and also will let you clarify regarding why useLayoutEffect is recommended over useEffect for DOM based operations (where you're targetting stuff that you can update before current browser paint)

Link to the diagram - https://github.com/donavon/hook-flow
Answer from Lakshya Thakur on Stack OverflowThe following diagram always helps me to visualize the flow of hooks and also will let you clarify regarding why useLayoutEffect is recommended over useEffect for DOM based operations (where you're targetting stuff that you can update before current browser paint)

Link to the diagram - https://github.com/donavon/hook-flow
If you don't have DOM manipulating code in the hook and only reading layout useEffect will do just fine.
If you do have DOM manipulating code in the useEffect and see screen flickering move this code to useLayoutEffect.
It goes like this:
- Render
- useLayoutEffect (synchronously after all DOM mutations)
- Paint
- useEffect