0Pricing
Sveltejs Academy · Lesson

onMount: Running After Render

Execute code after the component has been added to the DOM.

onMount Purpose

onMount runs after the component is added to the DOM. Ideal for kicking off async work or accessing refs.

Import It

Import from svelte at the top of your script.

<script>
  import { onMount } from "svelte";
</script>

All lessons in this course

  1. onMount: Running After Render
  2. onDestroy: Cleanup
  3. beforeUpdate and afterUpdate
  4. tick(): Waiting for DOM Updates
← Back to Sveltejs Academy