user2167582
user2167582

Reputation: 6368

Why do you need to use React.Children to iterate children?

this sounds like a bad question, but since children is already an array, while not call .map directly? is it just for catching case where children is singular?

-- Edit -- enter image description here

enter image description here

Upvotes: 0

Views: 50

Answers (1)

Itsca
Itsca

Reputation: 394

Because children is not an array, is an opaque data structure, so that actually returns an array based on this.props.children

Here's the reference from the docs for more information.

https://reactjs.org/docs/react-api.html#reactchildren

Edit:

In the case of your edit is acts as an array because it includes several children, but it could also act as other data types depending on the number of children or if it has children at all, just like Charlie Martin pointed in his comment.

Upvotes: 1

Related Questions