# only-export-components

Rule `react/only-export-components`. 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.

- 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: #1899 by reach

## Linters

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

## Code examples

### Incorrect: the rule reports this

```jsx
// 1) Mixing util exports with components in unsupported ways
export const foo = () => {};      // util, not a component
export const Bar = () => <></>;   // component
```

```jsx
// 2) Anonymous default export (name is required)
export default function () {}
```

```jsx
// 3) Re-exporting everything hides what’s exported
export * from "./foo";
```

### Correct: the rule accepts this

```jsx
// Named or default component exports are fine
export default function Foo() {
  return null;
}
```

```jsx
// Utilities may coexist if allowed by options or naming conventions
const foo = () => {};
export const Bar = () => null;
```

```jsx
// Entrypoint files may render an imported component
import { App } from "./App";
createRoot(document.getElementById("root")).render(<App />);
```

Examples from the Oxlint documentation.

## Enable it

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "react"
  ],
  "rules": {
    "react/only-export-components": "error"
  }
}
```

## Related rules

- [react-refresh/only-export-components](https://lintradar.dev/rules/react-refresh/only-export-components.md): Validate that your components can safely be updated with Fast Refresh
- [react/prefer-function-component](https://lintradar.dev/rules/react/prefer-function-component.md): Enforces that React components are written as function components instead of class components.
- [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

---

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