Skip to content

Document how to send messages to children components #905

Open

Description

@jstarry

Not sure how formal the support for this feature should be, but at the moment is possible using the approach in the nested list example here:
https://github.com/yewstack/yew/blob/master/examples/nested_list/src/app.rs

So I think it deserves a write up in the docs

Activity

  1. muhuk commented on Jun 28, 2020

    @muhuk

    I wish there was a way that doesn't require us do:

    *props.weak_link.borrow_mut() = Some(link);

    A cleaner approach is perhaps, when the parent sets a prop named link, same ComponentLink can be passed to the child's create.


    I also tried using the props instead, but Clone requirement is the issue there.

  2. muhuk commented on Jul 5, 2020

    @muhuk

    I have found some sort of a solution that works in my use case. I need to pass a non-cloneable struct from parent to child. So I am now passing a callback with IN of ComponentLink<Child> to child in props. Then in child's create I pass a clone of its link to parent. Just wanted to share.

  3. ranile commented on Jan 1, 2022

    @ranile
    Member

    #2321 adds a section about component communication (see here). It suggests using contexts to communicate but there is no explanation on how to actually do it. Context documentation mostly consists of two giant code blocks. This needs improvement.

    Related: #2189

  4. DavidCks commented on Nov 4, 2022

    @DavidCks

    Since this is the first thing that comes up in google I thought I might aswell post my solution here: https://dev.to/davidcks/how-to-send-a-message-to-a-child-component-in-yew-503

    Basically I have a link field in my parent component which gets updated when a certain Message is received.
    I then send a message to the parent from within the child containing its Scope so it can update the parents field with that childs Scope.

    Now the Scope is available in the parent and messages can be dispatched.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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