Converting Frontend Framework Components to Custom Elements
Reactive Frontend Frameworks like React, Preact, and Vue implement their own virtual DOM systems. This vDOM is not directly compatible with the actual light and shadow DOM of the browser. However, often, there are ways to convert these components to proper web components. Preact has thepreact-custom-element
package
which makes it a matter of a few lines of code to convert a Preact component into a custom element.
Rendering into an HTMLElement
If your frontend framework is missing such a utility, or if you prefer to implement your own - e.g. because it is missing some functionality you need - you will need to implement your own. While this is usually not too difficult, it does require some knowledge of the internals of your framework.Preact
Thesubrender
function above is such an example:
React
Asubrender
function for React is very similar: