Should I write new React code with class components?
No. Write new code with functional components and hooks, which are the modern standard. Use class components only to read existing code or to answer interview questions about lifecycle methods.
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
