Skip to content

Type of children prop field should dictate the value used in createElement #164

Closed
@athanclark

Description

@athanclark

Firstly, I think we should do-away with the Children foreign data type, which aims to represent the prop field. It's opaque, and doesn't accurately represent the purpose of the prop type.

The existence of the children prop, in React's perspective, means that the component should be treated as one that can have children (i.e. <Foo> ... </Foo>, rather than <Foo />).

I believe the createElement function should have a type similar to

createElement :: forall props children. ReactClass (children :: children | props) -> { | props } -> children -> ReactElement

(more or less, disregarding the ReactPropFields constraint). This would allow for natural semantic consistency with React 16.x's Context, where a Consumer has a children prop of children :: a -> ReactElement | ....

Furthermore, unitary components (i.e. <Foo />) would be created with a different function

createElement' :: forall props. Lacks "children" props => ReactClass props -> { | props } -> ReactElement

strictly because the ReactClass's props lacks the children attribute.

This way, the children attribute's value could just be coerced by its usage in createElement, whether it be an array of ReactElements, a single ReactElement, a fragment or whathaveyou. But more consistently, as a function for a Context's Consumer, making the paradigm more readily available for end-users.

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