react/no-clone-element
react plugin · restriction
{
"plugins": [
"react"
],
"rules": {
"react/no-clone-element": "error"
}
}Prevents the usage of React.cloneElement, which is considered an anti-pattern in React.
import { cloneElement } from "react";
function List({ children }) {
const [selectedIndex, setSelectedIndex] = useState(0);
return (
<div className="List">
{Children.map(children, (child, index) =>
cloneElement(child, {
isHighlighted: index === selectedIndex
})
)}
</div>
);
}// Using a map with a `renderItem` function prop instead.
function List({ items, renderItem }) {
const [selectedIndex, setSelectedIndex] = useState(0);
return (
<div className="List">
{items.map((item, index) => {
const isHighlighted = index === selectedIndex;
return renderItem(item, isHighlighted);
})}
</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-clone-element
react plugin · restriction
{
"plugins": [
"react"
],
"rules": {
"react/no-clone-element": "error"
}
}Biome does not have this rule.
Disallows the usage of React.Children, as it is considered a bad practice.
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