lifecycle methods in class components are used to control the behaviour of components during different phases of their lifecycle. However, with the introduction of React Hooks and the Fiber architecture, the concept of lifecycle methods has evolved.
constructor
static getDerivedStateFromProps
render()
componentDidMount()
UNSAFE_componentWillMount()
static getDerivedStateFromProps()
shouldComponentUpdate()
render()
getSnapshotBeforeUpdate()
componentDidUpdate()
UNSAFE_componentWillUpdate()
UNSAFE_componentWillReceiveProps()
componentWillUnmount()
static getDerivedStateFromError()
componentDidCatch()
If you add a console.log in componentDidMount of a class component, when will it appear relative to the first render?
How would you fetch data when a component first appears on screen using lifecycle methods?
What happens if you call setState inside componentWillUnmount?
You notice that a component's UI doesn't update after props change. Which lifecycle method would you check and why?
During a refactor, componentWillReceiveProps caused a bug when props changed rapidly. How would you fix it using newer lifecycle methods?
Explain why using componentDidUpdate to trigger an API call caused an infinite loop, and how to prevent it.
Design a reusable modal component that needs to clean up event listeners and timers. Which lifecycle methods would you use and what edge cases must you handle?
In a large app, you need to coordinate animations across multiple components during mounting and unmounting. How would you orchestrate this using lifecycle hooks while minimizing performance impact?
How would you migrate a legacy class component that relies on componentWillMount to a functional component with hooks, ensuring no change in behavior?
Your team is planning to deprecate all class components in a codebase of 500+ components. What strategy would you propose for handling lifecycle methods during the migration, and how would you mitigate risk across teams?
Discuss the trade‑offs of using getDerivedStateFromProps versus moving state management to a global store in a high‑traffic dashboard, considering render performance and maintainability.
How would you set up a shared library that abstracts common lifecycle patterns (e.g., data fetching, subscription cleanup) for both class and functional components, and what versioning considerations would you enforce?