Questions:
What is the difference between useEffect and useLayoutEffect?
This question is asked by the interviewer to assess your understanding of the rendering process in React as choosing the wrong method can have impact on the performance.
Sample Answer:
The useEffect does not affect the browser nor does it blocks the browser as it runs after the paint of the content to the user.
The useLayoutEffect method runs in synchronous after all the DOM mutations but just before the browser repaints. This methos is to be used for DOM measurements or synchronous updates.
If you wish to avoid blocking the UI, it is better to use the “useEffect” method.