Rules
no-children-for-each
Full Name in eslint-plugin-react-x
react-x/no-children-for-eachFull Name in @eslint-react/eslint-plugin
@eslint-react/no-children-for-eachPresets
- x
- recommended
- recommended-typescript
- recommended-type-checked
Description
Disallow the use of Children.forEach from the react package.
Using Children 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.forEach(children, (child, index) => {
    result.push(child);
    result.push(<hr key={index} />);
  });
  // ...
}Implementation
Further Reading
See Also
- no-children-count
 Prevents the use of- Children.countfrom the- reactpackage.
- no-children-map
 Prevents the use of- Children.mapfrom the- reactpackage.
- no-children-only
 Prevents the use of- Children.onlyfrom the- reactpackage.
- no-children-to-array
 Prevents the use of- Children.toArrayfrom the- reactpackage.