Skip to content

Express required children proptype #1752

Closed
@slorber

Description

@slorber

Hi,

I want a component to have at least one required children.
As children can be both a singe element or an array it is not easy (to avoid useless array allocation according to the doc).

I don't know which is the simplest way to do so but come up with this syntax:

        children: React.PropTypes.oneOfType([
            React.PropTypes.component,
            React.PropTypes.arrayOf(React.PropTypes.component)
        ]),

I guess my usecase can be quite common for people building Modals and things like that.
Maybe it would be nice to have a simpler way to express the children is required?

Maybe React.PropTypes.any.isRequired will do the same job? Is there some kind of guarantee that the children prop will never be a different type than component or array(component) ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions