In a recent interview, I was given this React snippet: ``` import { useEffect, useLayoutEffect } from "react"; export default function Dummy() { useLayoutEffect(() => { console.log(1); }, []); useEffect(() => { console.log(2); }, []); console.log(3); return <div>{console.log(4)}</div>; } ``` Here’s the output: 3 4 1 2 This question actually tested how well I understand the lifecycle of a functional component in React. React’s flow goes like this: Render → Commit → Paint → Effects - 3 runs during the render phase - 4 runs while rendering JSX - 1 (useLayoutEffect) runs after the DOM updates but before the browser paints - 2 (useEffect) runs after the paint, asynchronously Would love to know how you reasoned through this or any similar conceptual interview question you came across! #ReactJS #ReactHooks #FrontendDevelopment #CodingInterview #useEffect #useLayoutEffect #WebDevelopment
Isn't this very basic? There is nothing tricky about it
Nicely explained