APIs
Children.forEach
Calls a function for each traversed child without building an output array. Avoid side effects during rendering.
Formal Syntax & Structure
react syntaxreact
Children.forEach(children, fn)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| children | React children | Opaque children value. |
| fn | function | Receives a child and its index. |
Return Value
undefined
No transformed result.
Working Example
Example Snippetreact
import { Children } from 'react';const labels = [];Children.forEach(['A', 'B'], child => labels.push(child));console.log(labels);