Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Web Components can't be directly used in React due to these limitations documented at https://custom-elements-everywhere.com/

Handling data React passes all data to Custom Elements in the form of HTML attributes. For primitive data this is fine, but the system breaks down when passing rich data, like objects or arrays. In these instances you end up with stringified values like some-attr="[object Object]" which can't actually be used.

Handling events Because React implements its own synthetic event system, it cannot listen for DOM events coming from Custom Elements without the use of a workaround. Developers will need to reference their Custom Elements using a ref and manually attach event listeners with addEventListener. This makes working with Custom Elements cumbersome.

Stencil provides wrapping to circumvent these limitations. https://stenciljs.com/docs/react



This is a pain point of React + web components, but I’ve heard they’re trying to solve it in the next major version. In the meantime, I built a wrapper that lets you use custom elements as if they were React components. [1]

1 - https://shoelace.style/getting-started/usage?id=react


That is React's problem in fighting against Web Components.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: