onMount & onCleanup in SolidJS
From the SolidJS cheat sheet ยท Lifecycle ยท verified Jul 2026
onMount & onCleanup
Run code after the component mounts or when it unmounts.
typescript
// Quick Reference
import { onMount, onCleanup } from "solid-js";
onMount(() => {
console.log("Component mounted");
});
onCleanup(() => {
console.log("Component unmounted");
});๐ก onMount runs once after the component is first rendered to the DOM
โก onCleanup works in both components and effects โ cleans up between re-runs too
๐ Since components run only once, you can set up intervals directly in the function body
๐ข onMount is equivalent to createEffect that runs only on first execution
lifecyclemountcleanup