pull/8136/head
Simon H 3 years ago committed by GitHub
parent c941525aac
commit cda63cfd2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -27,6 +27,8 @@ export function beforeUpdate(fn: () => any) {
* 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` does not run inside a [server-side component](/docs#run-time-server-side-component-api).
*
* https://svelte.dev/docs#run-time-svelte-onmount

@ -0,0 +1,58 @@
import { onMount } from '$runtime/index';
// sync and no return
onMount(() => {
console.log("mounted");
});
// sync and return value
onMount(() => {
return 'done';
});
// sync and return sync
onMount(() => {
return () => {
return "done";
};
});
// sync and return async
onMount(() => {
return async () => {
const res = await fetch('');
return res;
};
});
// async and no return
onMount(async () => {
await fetch('');
});
// async and return value
onMount(async () => {
const res = await fetch('');
return res;
});
// @ts-expect-error async and return sync
onMount(async () => {
return () => {
return "done";
};
});
// @ts-expect-error async and return async
onMount(async () => {
return async () => {
const res = await fetch('');
return res;
};
});
// @ts-expect-error async and return any
onMount(async () => {
const a: any = null as any;
return a;
});
Loading…
Cancel
Save