# prefer-function-component

Rule `react/prefer-function-component`. Enforces that React components are written as function components instead of class components.

- Source: react
- Technologies: React
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1900 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| Oxlint | `react/prefer-function-component` | no | no | plugin `react`, category restriction | [docs](https://oxc.rs/docs/guide/usage/linter/rules/react/prefer-function-component.html) |

## Code examples

### Incorrect: the rule reports this

```jsx
class Foo extends React.Component {
  render() {
    return <div>{this.props.foo}</div>;
  }
}

class Bar extends React.PureComponent {
  render() {
    return <div>{this.props.bar}</div>;
  }
}
```

### Correct: the rule accepts this

```jsx
const Foo = function(props) {
  return <div>{props.foo}</div>;
};

const Bar = ({ bar }) => <div>{bar}</div>;
```

Examples from the Oxlint documentation.

## Enable it

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "react"
  ],
  "rules": {
    "react/prefer-function-component": "error"
  }
}
```

## Related rules

- [react/only-export-components](https://lintradar.dev/rules/react/only-export-components.md): 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.
- [react/no-react-children](https://lintradar.dev/rules/react/no-react-children.md): Disallows the usage of `React.Children`, as it is considered a bad practice.
- [react/no-clone-element](https://lintradar.dev/rules/react/no-clone-element.md): Prevents the usage of `React.cloneElement`, which is considered an anti-pattern in React.
- [react/sort-prop-types](https://lintradar.dev/rules/react/sort-prop-types.md): Enforce propTypes declarations alphabetical sorting
- [react/sort-default-props](https://lintradar.dev/rules/react/sort-default-props.md): Enforce defaultProps declarations alphabetical sorting
- [react/require-optimization](https://lintradar.dev/rules/react/require-optimization.md): Enforce React components to have a shouldComponentUpdate method

---

Web page: https://lintradar.dev/rules/react/prefer-function-component. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
