Documentation
Rules
no-children-for-each

no-children-for-each

Rule category

Restriction.

What it does

Prevents the use of Children.forEach from the react package.

Why is this bad?

Using Children is uncommon and can lead to fragile code. See common alternatives.

Examples

Failing

import React, { Children } from "react";
 
interface ExampleProps {
  children: React.ReactNode;
}
 
function Example({ children }: ExampleProps) {
  const result = [];
  Children.forEach(children, (child, index) => {
    result.push(child);
    result.push(<hr key={index} />);
  });
  // ...
}

Further reading