APIs

Children.toArray

Converts the opaque children structure into a flat array, omitting empty nodes. React calculates element keys to preserve identity across flattening; do not rely on their textual format.

Formal Syntax & Structure

react syntaxreact
Children.toArray(children)

Parameters & Attributes

NameTypeDescription
childrenReact childrenOpaque children value.

Return Value

array

Flattened non-empty child nodes.

Working Example

Example Snippetreact
import { Children } from 'react';console.log(Children.toArray(['A', null, ['B']]).length);
React Reference