MDN does a fairly good job of covering the lifecycle events for web components but one in particular got my attention today, disconnectedcallback. As kind of the inverse of connectedCallback, it will be fired when an instance of your custom element is removed from the DOM. While I didn't doubt this worked as advertised, I wanted to build a quick demo myself so I could see it in action. Let's start off with a component that demonstrates why this event is needed.
Raymond Camden
@raymondcamden
Father, husband, web nerd who builds too many cat-based demos. Love Jamstack, serverless, JavaScript, Python.
STORY’S CREDIBILITY
Code License
The code in this story is for educational purposes. The readers are solely responsible for whatever they build with it.