Lifecycle Interview Questions
4 curated lifecycle interview questions with detailed answers and examples.
← Browse all interview questionsuseEffect with an empty dependency array replaces componentDidMount. With a dependency array it replaces componentDidUpdate for specific values. With a cleanup return it replaces componentWillUnmount. React.memo replaces shouldComponentUpdate. useLayoutEffect replaces getSnapshotBeforeUpdate.
Use useEffect to run logic after state updates, and useLayoutEffect when you need to act before the browser paints.
Use useEffect with an empty dependency array to run logic once after the first render, equivalent to componentDidMount.
Use useEffect without a dependency array to run logic after every render, and understand when this pattern is appropriate versus problematic.