-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accessing children
#106
Comments
We explored a few options for direct access, but the only option we found entailed crawling the DOM children and turning them into React nodes; while functional, it was very messy and create a lot of React If you just want to render that text, and don't need access to the value, slots are what you want. Given how you've written the above component, you can render that text anywhere you want by rendering <my-component>
<span slot="content1">some text I want access to in react</span>
<p slot="content2">some other content I want access to in react</p>
</my-component> Then render these with If you need direct access to the value, I would suggest putting it in an attribute on the WC, or setting it on a property after the component is mounted. |
If you think this would benefit from further discussion, or if not, I'd invite you to join our community discord. There are quite a few threads there about R2WC, and t's become a really great spot to ask questions, share knowledge, and connect about other interests too. |
Thanks so much. I actually ended up solving it with a slot although not exactly what I wanted. |
If you can explain your needs a bit more, I might be able to incorporate something into a future version that solves the problem better. |
I solved as follow:
how about put this logic into |
what cause this case is confused me. |
I have got the reason in this code. it's not a limit by custom element but React. React render need a root element as the root. so you provide
To avoid prevent this issue. how about select or create a root instead of
|
@christopherjbaker check this please. |
replace all origin children or create a new child root node maybe could be a property choice when using custom html. |
I started conversation on this topic a while ago on Discord as well, here is the link for the thread for reference: https://discord.com/channels/1007137664606150746/1113836418716942358/1113836418716942358 |
I have also encountered this problem. This problem is too critical. If children cannot include nested components, and do this in attributes, the converted components will be quite troublesome to use. |
That's a usecase we would need as well for web-components. An Accordeon-Component for example doesn't need to know it's children beforehand and it would be necessary to just be able to drop other components/content in. Is there a workaround that works in the meantime? |
Let's say I have this webcomponent
I assumed the text would be available as
children
in the react component, but it's not as far as I can tell. Can I accessthis.textContent
somehow instead?The text was updated successfully, but these errors were encountered: