Skip to content

Lifecycle Hooks

beforeMount, onMount, beforeUpdate, onUpdate, onDestroy

Hooks to manage the life cycle of the component.

javascript
import { beforeMount, onMount, beforeUpdate, onUpdate, onDestroy } from "esor";

// It is executed before mounting the component
beforeMount(() => {...});

// It is executed after mounting the component
onMount(() => {...});

// Runs before upgrading
beforeUpdate(() => {...});

// Runs after upgrading
onUpdate(() => {...});

// Executed when the component is destroyed
onDestroy(() => {...});

Example Life Cycle

javascript
import { component, html, onMount, onDestroy } from "esor";

component("lifecycle-demo", () => {
  onMount(() => {
    console.log("Assembled component");
  });

  onDestroy(() => {
    console.log("Component destroyed");
  });

  return html`<div>Life Cycle Demo</div>`;
});