What is the difference between state in class and functional components?
Class components store state in this.state and update it with this.setState. Functional components use the useState hook, which returns a state value and a setter function. The mental model is similar, but the syntax differs.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Class Components vs Functional Components: Which Should You Use?
Use functional components for all new code. They are the modern standard, simpler, and fully capable thanks to hooks. Use class components only to read existing code or answer interview questions.
Hooks gave functional components every capability class components had, with less boilerplate, easier code reuse through custom hooks, and better tooling support. The React team and ecosystem moved to functional components.
No. Hooks only work in functional components. This is one of the rules of hooks. If you need state or side effects in a class component, you must convert it to a functional component.
Still have questions?
Browse all our FAQs or reach out to our support team
