react/prefer-function-component
react plugin · restriction
{
"plugins": [
"react"
],
"rules": {
"react/prefer-function-component": "error"
}
}Enforces that React components are written as function components instead of class components.
class Foo extends React.Component {
render() {
return <div>{this.props.foo}</div>;
}
}
class Bar extends React.PureComponent {
render() {
return <div>{this.props.bar}</div>;
}
}const Foo = function(props) {
return <div>{props.foo}</div>;
};
const Bar = ({ bar }) => <div>{bar}</div>;Examples from the Oxlint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
ESLint does not have this rule.
react/prefer-function-component
react plugin · restriction
{
"plugins": [
"react"
],
"rules": {
"react/prefer-function-component": "error"
}
}Biome does not have this rule.
Ensures that modules only **export React components (and related HMR-safe items)** so that Fast Refresh (a.k.a. hot reloading) can safely preserve component state. Concretely, it validates the shape of your module’s exports and common entrypoints (e.g. createRoot(...).render(<App />)) to match what integrations like react-refresh expect.
Disallows the usage of React.Children, as it is considered a bad practice.
Prevents the usage of React.cloneElement, which is considered an anti-pattern in React.
Enforce React components to have a shouldComponentUpdate method