Skip to content

React.children do not take Functions as Children under consideration #11888

Closed
@michal-lipski

Description

@michal-lipski

My component can have multiple children components. They can be of different types: Strings, JSX Components and functions.

<ChildrenCounter>
  First
  {() => <div>Second</div>}
</ChildrenCounter>

I wanted to render them using React.children.map helper function that unwraps the children opaque data structure. The problem is that children defined as functions seem to be ignored by React.children.map, React.children.count and other helper functions. See the example:

https://jsfiddle.net/bpdsraah/2/

I can access them and render directly from props.children wrapper but it is not a convenient way as one can never know for sure what type it will be.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions