Facebook Pixel

React Lifecycle and Class Component Interview Questions

Lifecycle and class component questions still appear in interviews. Here are the common ones and how to answer them well.

React Lifecycle and Class Component Interview Questions

Even in 2025, interviewers ask about the React lifecycle and class components. These questions test your depth. Here are the common ones.

What are the lifecycle phases of a React component?

Mounting, updating, and unmounting. Mounting is when the component is added to the DOM, updating is when it re-renders due to state or props changes, and unmounting is when it is removed.

What does componentDidMount do?

It runs after the component is added to the DOM. You fetch data, set up subscriptions, and start timers here. It maps to useEffect with an empty dependency array.

What does componentWillUnmount do?

It runs right before the component is removed. You clean up subscriptions, timers, and listeners here to prevent leaks. It maps to the cleanup function returned from useEffect.

What is the difference between componentDidMount and componentDidUpdate?

componentDidMount runs once, after mount. componentDidUpdate runs after every update caused by state or props changes. They handle different moments in the lifecycle.

How do lifecycle methods map to hooks?

constructor maps to useState initial values. componentDidMount maps to useEffect with an empty array. componentDidUpdate maps to useEffect with dependencies. componentWillUnmount maps to the useEffect cleanup function.

How to Answer Well

Connect class concepts to hooks. Interviewers want to see you understand both, and that you know why React moved to hooks. Show the mapping, not just the definitions.

The Takeaway

Know the lifecycle phases, componentDidMount, componentWillUnmount, the difference between mount and update methods, and how each maps to hooks. Connecting class concepts to hooks shows depth.

Mounting, updating, and unmounting. Mounting is when the component is added to the DOM, updating is when it re-renders due to state or props changes, and unmounting is when it is removed.

It runs after the component is added to the DOM. You fetch data, set up subscriptions, and start timers here. It maps to useEffect with an empty dependency array in functional components.

It runs right before the component is removed from the DOM. You clean up subscriptions, timers, and listeners here to prevent leaks. It maps to the cleanup function returned from useEffect.

componentDidMount runs once, after mount. componentDidUpdate runs after every update caused by state or props changes. They handle different moments in the component lifecycle.

constructor maps to useState initial values. componentDidMount maps to useEffect with an empty array. componentDidUpdate maps to useEffect with dependencies. componentWillUnmount maps to the useEffect cleanup function.

Ready to master React completely?

Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.

Please Login.
Please Login.
Please Login.
Please Login.