When to use useEffect or useLayoutEffect
I will go to my grave believing useEffect is one of the most abused and unecissary hooks a lot of the time.
I'm not saying it doesn't have it's place, but too often people are using it to change data on render, which just causes a new render. Instead they could just isolate the data change from react entirely (which makes sense given react is a view layer and not a full mvc) and have the first render be a cause of the change.
I can't count the number of times I've seen people have a useEffect that checks to see if a useState value changed and loads data based on it. It's like... Just load the data where the useState change was triggered!
More on reddit.comreactjs - Is `useLayoutEffect` preferable to `useEffect` when reading layout? - Stack Overflow
React documentation on useLayoutEffect makes me confused
what is the point of `useRef` + `useLayoutEffect` in this scenario?
Videos
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
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