Created
April 18, 2023 19:56
-
-
Save ekashida/9e1594a9ea0b044d5754698a546d36eb to your computer and use it in GitHub Desktop.
lwc-external
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<p>foobarbaz</p> | |
<div lwc:dom="manual"></div> | |
<my-foobarbaz lwc:external foo="barbaz">lwc:external</my-foobarbaz> | |
</template |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LightningElement } from 'lwc'; | |
export default class NativeCustomElements extends LightningElement { | |
rendered = false; | |
renderedCallback() { | |
if (!this.rendered) { | |
this.rendered = true; | |
const div = this.template.querySelector('div'); | |
div.innerHTML = `<my-foobarbaz></my-foobarbaz>`; | |
customElements.define("my-foobarbaz", class MyCounter extends HTMLElement { | |
constructor() { | |
super(); | |
this.__shadowRoot = this.attachShadow({ mode: 'closed' }); | |
this.__shadowRoot.innerHTML = 'CONSTRUCTOR'; | |
} | |
connectedCallback() { | |
this.__shadowRoot.innerHTML = `${this.__shadowRoot.innerHTML} CONNECTEDCALLBACK`; | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment