new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Svelte · Language · all subjects

component lifecycle

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

lifecycle_outside_component pitfall

Calling lifecycle methods like `onMount()` inside event handlers or other functions, rather than at the top level of the component script, causes a lifecycle_outside_component error. These methods must be called synchronously at the top level during component initialization.

onDestroy runs immediately before component unmount

onDestroy schedules a callback to run immediately before the component is unmounted. Out of onMount, beforeUpdate, afterUpdate and onDestroy, this is the only one that runs inside a server-side component.

onMount schedules function to run once on mount

onMount schedules a function to run as soon as the component has been mounted to the DOM. Unlike $effect, the provided function only runs once. It must be called during the component's initialisation but doesn't need to live inside the component; it can be called from an external module. If a function is returned synchronously from onMount, it will be called when the component is unmounted. onMount functions do not run during server-side rendering.

lifecycle_legacy_only error

The error '`%name%(...)` cannot be used in runes mode' occurs when attempting to use a legacy lifecycle function in runes mode.

lifecycle_outside_component shared error

The error '`%name%(...)` can only be used during component initialisation' occurs when lifecycle methods are called outside the top level of the instance script. Lifecycle methods must be invoked during the initial execution of a component's script block, not inside event handlers or other functions.

Give your agent this brain