react/no-react-children
react plugin · restriction
{
"plugins": [
"react"
],
"rules": {
"react/no-react-children": "error"
}
}Disallows the usage of React.Children, as it is considered a bad practice.
import { Children } from 'react';
Children.toArray(children);
Children.map(children, child => <div>{child}</div>);
Children.only(children);
Children.count(children);
Children.forEach(children, (child, index) => {});import React from 'react';
function Table({ children }) {
const mappedChildren = React.Children.map(children, (child) =>
<tr>{child}</tr>
);
return <table>{mappedChildren}</table>;
}import { Children } from 'react';
function RowList({ children }) {
return (
<>
<h1>Total rows: {Children.count(children)}</h1>
</>
);
}function Card({ children }) {
return (
<div className="card">
{children}
</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/no-react-children
react plugin · restriction
{
"plugins": [
"react"
],
"rules": {
"react/no-react-children": "error"
}
}Biome does not have this rule.
Prevents the usage of React.cloneElement, which is considered an anti-pattern in React.
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.
Enforces that React components are written as function components instead of class components.
Enforce React components to have a shouldComponentUpdate method