react/only-export-components
react plugin · restriction
{
"plugins": [
"react"
],
"rules": {
"react/only-export-components": "error"
}
}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.
// 1) Mixing util exports with components in unsupported ways
export const foo = () => {}; // util, not a component
export const Bar = () => <></>; // component// 2) Anonymous default export (name is required)
export default function () {}// 3) Re-exporting everything hides what’s exported
export * from "./foo";// Named or default component exports are fine
export default function Foo() {
return null;
}// Utilities may coexist if allowed by options or naming conventions
const foo = () => {};
export const Bar = () => null;// Entrypoint files may render an imported component
import { App } from "./App";
createRoot(document.getElementById("root")).render(<App />);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/only-export-components
react plugin · restriction
{
"plugins": [
"react"
],
"rules": {
"react/only-export-components": "error"
}
}Biome does not have this rule.
Validate that your components can safely be updated with Fast Refresh
Enforces that React components are written as function components instead of class components.
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.