[@lit-labs/context] Context not available when children are not part of render() method #3790
Unanswered
BregtDeLange
asked this question in
Q&A
Replies: 1 comment
-
Slotted children components of a context provider can still consume the context. See https://lit.dev/playground/#gist=6b69a35321ee746605f877a5ed03ee8d If it's not working for you, we'd need to see a reproduction. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Just started getting into more complex usages for Lit, and found out about the @lit-labs/context
I have an API that returns product data that I want to make available to different components. I used to to this with events, and children subscribing to the event that is created at root level. However, my components are without Shadow DOM, because I want to style them from the Light DOM.
I can get my data working with the Context setup, when I have my child web components are part of the render method. But that's not how I use my web components in this project. The root element does not define how the HTML structure of its children should be. I want my children to be dependent on the root in terms of data and functionality, but I don't want the HTML to be forced from the render() method on the root. I want my child elements be placed inside elements chosen in the light DOM.
Here's an example
However, it obviously works when I do this in my root.ts, but that is not really how my site works right now. I want more freedom with the child components.
Did I forgot something in my desired setup? Or is that not possible with the @lib-labs/context package? I'd assumed that all children could subscribe to the events set by the context object, even if they're not part of the actual render method.
Beta Was this translation helpful? Give feedback.
All reactions