With typescript starter with create-react-app I got the following error: Property 'registerElement' does not exist on type 'Document'. Did you mean 'createElement'?
const proto = Object.create(HTMLElement.prototype, {
attachedCallback: {
value: function () {
const mountPoint = document.createElement('span')
const shadowRoot = this.createShadowRoot()
shadowRoot.appendChild(mountPoint)
ReactDOM.render(<App />, mountPoint)
retargetEvents(shadowRoot)
},
},
})
document.registerElement('my-custom-element', { prototype: proto })
I know this is a problem with type, but looks like registerElement is deprecated. Should we use window.customElements.define(...)
instead?