You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Document how to send messages to children components #905
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.
Reacted by Andrew Straw, Duy Do, Stepan Henek and nitnelave
#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.
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.
Activity
muhuk commentedon Jun 28, 2020
I wish there was a way that doesn't require us do:
A cleaner approach is perhaps, when the parent sets a prop named
link, sameComponentLinkcan be passed to the child'screate.I also tried using the props instead, but
Clonerequirement is the issue there.muhuk commentedon Jul 5, 2020
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
INofComponentLink<Child>to child in props. Then in child'screateI pass a clone of its link to parent. Just wanted to share.ranile commentedon Jan 1, 2022
#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
DavidCks commentedon Nov 4, 2022
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.