-
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
How to send children prop in the custom HTML element created #7
Comments
Can you share what your component looked like? |
Same problem. Example component: js/tsx: import * as React from 'react';
import * as PropTypes from 'prop-types';
export const Foobar = (props) => {
console.log({ props });
return (
<div>
headingtitle prop: { props.headingtitle }
<br />
children prop:<br />
{ props.children }
</div>
);
}
Foobar.propTypes = {
headingtitle: PropTypes.string,
children: PropTypes.node,
};
export default Foobar; import * as React from 'react';
import * as ReactDOM from 'react-dom';
import reactToWebComponent from 'react-to-webcomponent';
import { Foobar } from 'common/components/Foobar';
const FoobarAsWebComponent = reactToWebComponent(Foobar, React, ReactDOM);
customElements.define('foo-bar', FoobarAsWebComponent); HTML: <foo-bar headingtitle="Heading title prop">
<p>Todo lo que ves en nuestro catálogo. Tenemos a la venta más de 24.000.000 de lotes de más de 20.000 vendedores distintos.</p>
</foo-bar> console.log: |
I am having a similar issue. But its happening post build with the attribute passed to the custom element. |
Thanks @linuxonrails for trying to summarize this for me. I'm not actually much of a react dev (much more of a webcomponent dev). Just to confirm the expected behavior ... it seems like Is |
Not sure if I understand the problem but I can set props like this:
|
Not always Sometimes <MyChildAcceptingComponent>
<ChildComponent propA={valueA} />
</MyChildAcceptingComponent>
It's also possible to use <MyChildAcceptingComponent>
{
(someValue) => {
return (
<div>{someValue}</div>
)
}
}
</MyChildAcceptingComponent>
The most common case is the Typically React render cycle mounts root nodes (the parents) then leaf nodes - the outermost leaf would finish render first (the deepest child) and signal the parent that it's ready, then parent will be ready if it has no more children to render |
Or maybe this will have nothing to do with React I think we're expecting usage like this: <my-web-component-grid>
<custom-item>
<h4>Something</h4>
<span>Something<span>
<custom-item>
<my-web-component-grid> We're not using React code here so why should it matter? We just want to supply whatever comes out of Is it possible to update the interface of Like const FoobarAsWebComponent = reactToWebComponent(Foobar, React, ReactDOM, {
children: (containerNode, contentNode) => {
containerNode.replaceChildren(contentNode.cloneNode(true));
// or
containerNode.shadowRoot.replaceChildren(contentNode.cloneNode(true));
// or something else
}
}); And there can be a simple case where we just provide const FoobarAsWebComponent = reactToWebComponent(Foobar, React, ReactDOM, {
children: true
}); Which should add an unnamed slot in I think the word Unlike web components in React there's always only one slot - children. |
How is it going by now ? |
This is something we are looking into, but I don't have any progress updates at the moment. It is requiring some exploration because React expects children to be jsx or other renderable content that it can turn into DOM nodes; there's no way to give it content that is already DOM nodes. |
Unless there is something I don't understand, having "DOM children" can be done as described in this article (using a "slot"): |
@bertrand-riviere That does look promising! It will still require some exploration to integrate it in a generic way, but we'll be picking this up soon. |
Let say I want something inside the
<text-x> Hi </text-x>
, I tried using<text-x children="Hi"></text-x>
both didn't workThe text was updated successfully, but these errors were encountered: