Use Web Components as React Components.
Import reactCustomElements
as a module:
import * as reactCustomElements from 'https://gist.githack.com/jonathantneal/b3df57a4c59cd70e0d18437352586794/raw/reactCustomElements.esm.min.js'
const Shout = reactCustomElements.define('h-shout', class extends HTMLElement {
constructor() {
super().attachShadow({ mode: 'open' }).innerHTML = `<slot></slot>!`
}
})
ReactDOM.render(
React.createElement(Shout, {}, 'Hello')
)
Alternatively, import reactCustomElements
as a self-defined variable:
<script src="https://gist.githack.com/jonathantneal/b3df57a4c59cd70e0d18437352586794/raw/reactCustomElements.self.min.js"></script>
<script>
const Shout = reactCustomElements.define('h-shout', class extends HTMLElement {
constructor() {
super().attachShadow({ mode: 'open' }).innerHTML = `<slot></slot>!`
}
})
ReactDOM.render(
React.createElement(Shout, {}, 'Hello')
)
</script>
reactCustomElements.esm.min.js is 531 bytes, 337 bytes gzipped.
reactCustomElements.self.min.js is 545 bytes, 340 bytes gzipped.