Explain the difference between Class and Functional components.
Feature Class
Component
Functional
Component
Syntax ES6 Class Function
State this.state useState hook
Lifecycle methods Yes Use useEffect, etc.
Code size More verbose Cleaner and shorter
✅ Example:
Class:
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
Functional:
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}