Rules
no-children-only
Disallows the use of `Children.only` from the `react` package.
Full Name in eslint-plugin-react-x
react-x/no-children-onlyFull Name in @eslint-react/eslint-plugin
@eslint-react/no-children-onlyPresets
x
recommended
recommended-typescript
recommended-type-checked
strict
strict-typescript
strict-type-checked
Rule Details
Using Children is uncommon and can lead to fragile code. See common alternatives.
Common Violations
Invalid
import React, { Children } from "react";
interface MyComponentProps {
children: React.ReactNode;
}
function MyComponent({ children }: MyComponentProps) {
const element = Children.only(children);
// ...
}Resources
Further Reading
See Also
react-x/no-children-count
Disallows the use ofChildren.countfrom thereactpackage.react-x/no-children-for-each
Disallows the use ofChildren.forEachfrom thereactpackage.react-x/no-children-map
Disallows the use ofChildren.mapfrom thereactpackage.react-x/no-children-to-array
Disallows the use ofChildren.toArrayfrom thereactpackage.