Lifecycle
disconnectedCallback
The disconnectedCallback
is called when an element is removed from the DOM, e.g.
import Wafer from "@lamplightdev/wafer";
class MyExample extends Wafer() {
disconnectedCallback() {
console.log("disconnected");
}
}
customElements.define("my-element", MyExample);
const el = document.createElement("my-element");
// calls constructor
document.body.append(el);
// calls connectedCallback
el.remove();
// calls disconnectedCallback
// logs `disconnected`
Next: adoptedCallback
Previous: connectedCallback