react/prefer-stateless-function
eslint-plugin-react
No autofix
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/prefer-stateless-function": "error",
},
},
];Enforce stateless components to be written as a pure function
var Hello = createReactClass({
render: function() {
return <div>Hello {this.props.name}</div>;
}
});const Foo = function(props, context) {
const {
location
} = context.router;
return <div>{props.foo}</div>;
};class Foo extends React.Component {
render() {
if (!this.props.foo) {
return null
}
return <div>{this.props.foo}</div>;
}
}Examples from the ESLint documentation.
react/prefer-stateless-function
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/prefer-stateless-function": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Enforce a defaultProps definition for every prop that is not a required prop
Disallow declaring unused methods of component class