Reputation: 3994
I could find a lot of documentation to use a WebComponent using JSX in React. Well it's pretty straight forward...
But how to use a webcomponent in JavaScript with ReactJS ??
render: function(){
React.DOM.div {},
MyWebComponent {}, "hello"
Where 'MyWebComponent' is the component that I want to work with.
Upvotes: 0
Views: 125
Reputation: 3506
In JavaScript react.createElement takes an element or componant as the first argument, styles as the second argument, children as the third agrument.
import customComponent from 'my-custom-component';
var child = React.createElement(customComponent, null, 'Text Content');
var Element = React.createElement('div', { className: 'my-class' }, child);
render: function(){
{Element}
}
or you can do this
...
import customComponent from 'my-custom-component';
...
render: function(){
{React.createElement('div', { className: 'my-class' },customComponent );}
}
Upvotes: 3
Reputation: 656
As stated in the official react site you should be able to use web components with react
render: function(){
return <div><MyWebComponent>hello</MyWebComponent></div>;
}
here is the same example in pure js
render: function render() {
return React.createElement(
"div",
null,
React.createElement(
MyWebComponent,
null,
"hello"
)
);
}
Upvotes: 2