react/no-this-in-sfc
eslint-plugin-react
No autofix
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/no-this-in-sfc": "error",
},
},
];Disallow this from being used in stateless functional components
function Foo(props) {
return (
<div>{this.props.bar}</div>
);
}function Foo(props) {
const { bar } = this.props;
return (
<div>{bar}</div>
);
}function Foo(props, context) {
return (
<div>
{this.context.foo ? this.props.bar : ''}
</div>
);
}function Foo(props) {
return (
<div>{props.bar}</div>
);
}function Foo(props) {
const { bar } = props;
return (
<div>{bar}</div>
);
}function Foo({ bar }) {
return (
<div>{bar}</div>
);
}Examples from the ESLint documentation.
react/no-this-in-sfc
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/no-this-in-sfc": "error",
},
},
];react/no-this-in-sfc
react plugin · correctness
{
"plugins": [
"react"
],
"rules": {
"react/no-this-in-sfc": "error"
}
}Biome does not have this rule.
Disallow usage of shouldComponentUpdate when extending React.PureComponent
Enforce ES5 or ES6 class for React Components
Enforce that namespaces are not used in React elements
Enforces where React component static properties should be positioned.
Disallows JSX context provider values from taking values that will cause needless rerenders