What should I know about class components?
Understand this.state and this.setState, the main lifecycle methods like componentDidMount and componentWillUnmount, and how to map them to hooks. That is enough to read legacy code and answer interview questions.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in What Are Class Components in React and Are They Still Relevant?
A class component is an ES6 class that extends React.Component. It holds state in this.state, updates it with this.setState, and uses lifecycle methods like componentDidMount to run side effects at specific points in the component's life.
Not for writing new code, but yes for reading existing code. Many production codebases still have class components, and interviewers still ask about lifecycle methods. You do not need to write them, but you should understand them.
Because class components split related logic across separate lifecycle methods, the this keyword confused beginners and caused binding bugs, and reusable stateful logic was hard to share. Hooks solved all of these with less boilerplate.
Still have questions?
Browse all our FAQs or reach out to our support team
