Skip to content

Correct Way to Pass a Callback Function to a Child #51

Closed
@born2defy

Description

@born2defy

I have been playing with this library, I am curious what the correct way is to pass a callback function to a child element and what the type should be? In the child who is expecting a call back function in its props, what should the type of the callback function be (especially if we don't know the type of the parent yet that will be providing the callback function)? It seems like all the event handlers are parameterized to a specific element's props and state.

Also - if the child itself is responding to an event (like a click event), is there any way for the child to respond to the event locally (make a state change) and then call the parent's callback? It seems like the types of the two event handling functions (child and parent) conflict.

Finally, is there any way to add a callback to a child's componentWillMount or other life cycles hooks? The ReactSpec is typed so that all the types in the spec must match, so if we ran a parent's callback on a child's mount function we would get type issues, no?

Just curious how others are handling this or if there is an idiomatic way of solving this without having to put all the state together in one place.

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