Skip to content

Sharing data & state between components #5449

Answered by EisenbergEffect
KingOfTac asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, you've got a few options.

If you want the parent component to work with any direct child, then I recommend that you use the slotted directive to keep a sync'd array of child nodes and get change notifications when children change. When a change happens, you can loop through the slotted children and manipulate them in whatever way you want. So, if you want to check them to see if they support a specific API, such as having a value property, you could do that. The nice thing about this is that the logic is in a single element (the parent) regardless of what type of child you add. As long as the child elements conform to some interface, the parent can work with them. If you need child no…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
1 reply
@KingOfTac
Comment options

KingOfTac Dec 8, 2021
Collaborator Author

Comment options

You must be logged in to vote
7 replies
@KingOfTac
Comment options

KingOfTac Dec 10, 2021
Collaborator Author

@EisenbergEffect
Comment options

@KingOfTac
Comment options

KingOfTac Dec 11, 2021
Collaborator Author

@EisenbergEffect
Comment options

@KingOfTac
Comment options

KingOfTac Apr 9, 2022
Collaborator Author

Answer selected by KingOfTac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants