react/no-class-component
Rule category
Restriction.
What it does
Prevents the use of class component
in React.
Why is this bad?
Component is the base class for the React components defined as JavaScript classes. Class components are still supported by React, but we don’t recommend using them in new code.
It is recommended to define components as functions instead of classes. See how to migrate (opens in a new tab).
Examples
This rule aims to prevent usage of class components in React.
❌ Incorrect
class Greeting extends Component {
render() {
return <h1>Hello, {this.props.name}!</h1>;
}
}
✅ Correct
function Greeting(props) {
return <h1>Hello, {props.name}!</h1>;
}