DocumentationRulesno-children-to-array

no-children-to-array

Rule category

Restriction.

What it does

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

Why is this bad?

Using Children.toArray 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.toArray(children);
  result.reverse();
  // ...
}

Further reading