MCPcopy
hub / github.com/sveltejs/svelte / onMount

Function onMount

packages/svelte/src/index-client.js:91–104  ·  view source on GitHub ↗
(fn)

Source from the content-addressed store, hash-verified

89 * @returns {void}
90 */
91export function onMount(fn) {
92 if (component_context === null) {
93 e.lifecycle_outside_component('onMount');
94 }
95
96 if (legacy_mode_flag && component_context.l !== null) {
97 init_update_callbacks(component_context).m.push(fn);
98 } else {
99 user_effect(() => {
100 const cleanup = untrack(fn);
101 if (typeof cleanup === 'function') return /** @type {() => void} */ (cleanup);
102 });
103 }
104}
105
106/**
107 * Schedules a callback to run immediately before the component is unmounted.

Callers 2

on-mount.tsFile · 0.90
onDestroyFunction · 0.85

Calls 4

user_effectFunction · 0.90
untrackFunction · 0.90
init_update_callbacksFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected