What are the differences between functional and class components?
Learn how functional components differ from class components in React and why hooks have made functional components dominant.
beginnerFundamentalsreactclass componentsfunctional componentshooks
Published: 10/26/2025
Updated: 10/26/2025
React offers two component types: class components and functional components.
🧠Functional Components
- Simple JavaScript functions.
- Use hooks like
useState,useEffectfor state and side effects. - Easier to read, test, and optimize.
function Counter() {
const [count, setCount] = useState(0);
return <button onClick={() => setCount(count + 1)}>Clicked {count}</button>;
}
🧩 Class Components
- Use ES6 classes with render() methods.
- Lifecycle handled with methods like componentDidMount.
class Counter extends React.Component {
state = { count: 0 };
render() {
return (
<button onClick={() => this.setState({ count: this.state.count + 1 })}>
Clicked {this.state.count}
</button>
);
}
}
✅ Key Differences
| Aspect | Functional | Class |
|---|---|---|
| Syntax | Simpler | Verbose |
| State | Hooks | this.state |
| Lifecycle | useEffect | Lifecycle methods |
| Performance | Slightly better | Slight overhead |
Frequently Asked Questions
Which component type is preferred in modern React?
Functional components, since React Hooks allow managing state and lifecycle without classes.
Stay Updated
Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.