Skip to content

Instantly share code, notes, and snippets.

@JanDW
Created January 16, 2025 23:00
Show Gist options
  • Save JanDW/ce889bb0af9abedb6c51a77f5db69a1e to your computer and use it in GitHub Desktop.
Save JanDW/ce889bb0af9abedb6c51a77f5db69a1e to your computer and use it in GitHub Desktop.
Web component boilerplate with lifecycle callbacks.
class MyElement extends HTMLElement {
// Fires when an instance of the element is created or updated
constructor() {
super();
}
// Fires when an instance was inserted into the document
connectedCallback() {
}
// Fires when an instance was removed from the document
disconnectedCallback() {
}
// Fires when an attribute was added, removed, or updated
attributeChangedCallback(attrName, oldVal, newVal) {
}
// Fires when an element is moved to a new document
adoptedCallback() {
}
}
// Registers custom element
window.customElements.define('my-element', MyElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment