Skip to content

Commit 67a6d9b

Browse files
committed
update onMount docs
1 parent fbd1e51 commit 67a6d9b

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

packages/svelte/src/index-client.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ import { lifecycle_outside_component } from './internal/shared/errors.js';
99
import { legacy_mode_flag } from './internal/flags/index.js';
1010

1111
/**
12-
* The `onMount` function schedules a callback to run as soon as the component has been mounted to the DOM.
13-
* It must be called during the component's initialisation (but doesn't need to live *inside* the component;
14-
* it can be called from an external module).
12+
* `onMount`, like [`$effect`](https://svelte.dev/docs/svelte/$effect), schedules a function to run as soon as the component has been mounted to the DOM.
13+
* Unlike `$effect`, the provided function only runs once.
1514
*
16-
* If a function is returned _synchronously_ from `onMount`, it will be called when the component is unmounted.
15+
* It must be called during the component's initialisation (but doesn't need to live _inside_ the component;
16+
* it can be called from an external module). If a function is returned _synchronously_ from `onMount`,
17+
* it will be called when the component is unmounted.
1718
*
18-
* `onMount` does not run inside [server-side components](https://svelte.dev/docs/svelte/svelte-server#render).
19-
*
20-
* `onMount` runs only once. If you need reactivity, you can use [`$effect`](https://svelte.dev/docs/svelte/$effect),
21-
* which also runs when the component is mounted to the DOM.
19+
* `onMount` functions do not run during [server-side rendering](https://svelte.dev/docs/svelte/svelte-server#render).
2220
*
2321
* @template T
2422
* @param {() => NotFunction<T> | Promise<NotFunction<T>> | (() => any)} fn

packages/svelte/types/index.d.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,16 +348,14 @@ declare module 'svelte' {
348348
props: Props;
349349
});
350350
/**
351-
* The `onMount` function schedules a callback to run as soon as the component has been mounted to the DOM.
352-
* It must be called during the component's initialisation (but doesn't need to live *inside* the component;
353-
* it can be called from an external module).
351+
* `onMount`, like [`$effect`](https://svelte.dev/docs/svelte/$effect), schedules a function to run as soon as the component has been mounted to the DOM.
352+
* Unlike `$effect`, the provided function only runs once.
354353
*
355-
* If a function is returned _synchronously_ from `onMount`, it will be called when the component is unmounted.
354+
* It must be called during the component's initialisation (but doesn't need to live _inside_ the component;
355+
* it can be called from an external module). If a function is returned _synchronously_ from `onMount`,
356+
* it will be called when the component is unmounted.
356357
*
357-
* `onMount` does not run inside [server-side components](https://svelte.dev/docs/svelte/svelte-server#render).
358-
*
359-
* `onMount` runs only once. If you need reactivity, you can use [`$effect`](https://svelte.dev/docs/svelte/$effect),
360-
* which also runs when the component is mounted to the DOM.
358+
* `onMount` functions do not run during [server-side rendering](https://svelte.dev/docs/svelte/svelte-server#render).
361359
*
362360
* */
363361
export function onMount<T>(fn: () => NotFunction<T> | Promise<NotFunction<T>> | (() => any)): void;

0 commit comments

Comments
 (0)