The other thing I was worried about was that it was planned to after writing this web component lib, to wrap these components in React. Does anyone have any experience or insights into a React wrapped web component lib?
The other thing I was worried about was that it was planned to after writing this web component lib, to wrap these components in React. Does anyone have any experience or insights into a React wrapped web component lib?
Unfortunately it seems facebook isn't prioritizing fixing issues like this.
I'd suggest using preact if you want a framework that's more compatible with web components but gives you the React experience.
class App extends React.Component {
render() {
return (
<my-component custom-attribute={value}></my-component>
)
}
}
In your webcomponent just make sure you listen to changes to that attribute like so: static get observedAttributes() {
return ['custom-attribute']
}
Then you can decide how the component changes whenever that attribute is updated by using the `attributeChangedCallback` function. Alternatively, use a base element that incorporates a render() function which will automatically update everything in the shadowdom.Main difference is it becomes much harder to pass complex data structures. Passing strings is easy, but passing an array of data isn't feasible with this model.
So you can't take existing React libraries and 1:1 map them to web components. That approach only works for 'leaf' components that accept no children.