Rules
no-children-to-array
Full Name in eslint-plugin-react-x
react-x/no-children-to-arrayFull Name in @eslint-react/eslint-plugin
@eslint-react/no-children-to-arrayPresets
xrecommendedrecommended-typescriptrecommended-type-checked
Description
Disallow the use of Children.toArray from the react package.
Using Children.toArray is uncommon and can lead to fragile code. See common alternatives.
Examples
Failing
import React, { Children } from "react";
interface MyComponentProps {
children: React.ReactNode;
}
function MyComponent({ children }: MyComponentProps) {
const result = Children.toArray(children);
result.reverse();
// ...
}Implementation
Further Reading
See Also
no-children-countPrevents the use ofChildren.countfrom thereactpackage.no-children-for-each
Prevents the use ofChildren.forEachfrom thereactpackage.no-children-map
Prevents the use ofChildren.mapfrom thereactpackage.no-children-only
Prevents the use ofChildren.onlyfrom thereactpackage.