CWCO logo

v1.7.9

onDestroy

This livecycle function is called when the component is removed from the document.

class BFSButton extends WebComponent {

	onDestroy() {
		console.log('removed', this.mounted, this.isConnected)
	}
	
}

BFSButton.register();
const btn = new BFSButton();

// will trigger onMount call
document.body.appendChild(btn)

// will trigger onDestroy call
btn.remove()

It is an excellent livecycle to do clean-up work like:

  • Unsubscribe from observables;
  • Cancel a server request;
  • Clear timeout and intervals;
  • Clear requestAnimationFrame;