Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 14, 2024
1 parent 6a0e4a2 commit d66cb51
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
9 changes: 5 additions & 4 deletions documentation/docs/06-runtime/04-imperative-component-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@ Note that unlike calling `new App(...)` in Svelte 4, things like effects (includ

## `unmount`

Unmounts a component created with [`mount`](#mount) or [`hydrate`](#hydrate):
Unmounts a component that was previously created with [`mount`](#mount) or [`hydrate`](#hydrate).

If `options.outro` is `true`, [transitions](transition) will play before the component is removed from the DOM:

```js
// @errors: 1109
import { mount, unmount } from 'svelte';
import App from './App.svelte';

const app = mount(App, {...});
const app = mount(App, { target: document.body });

// later
unmount(app);
unmount(app, { outro: true });
```

## `render`
Expand Down
12 changes: 12 additions & 0 deletions packages/svelte/src/internal/client/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@ let mounted_components = new WeakMap();

/**
* Unmounts a component that was previously mounted using `mount` or `hydrate`.
*
* If `options.outro` is `true`, [transitions](https://svelte.dev/docs/svelte/transition) will play before the component is removed from the DOM.
*
* ```js
* import { mount, unmount } from 'svelte';
* import App from './App.svelte';
*
* const app = mount(App, { target: document.body });
*
* // later...
* unmount(app, { outro: true });
* ```
* @param {Record<string, any>} component
* @param {{ outro?: boolean }} [options]
*/
Expand Down
12 changes: 12 additions & 0 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,18 @@ declare module 'svelte' {
}): Exports;
/**
* Unmounts a component that was previously mounted using `mount` or `hydrate`.
*
* If `options.outro` is `true`, [transitions](https://svelte.dev/docs/svelte/transition) will play before the component is removed from the DOM.
*
* ```js
* import { mount, unmount } from 'svelte';
* import App from './App.svelte';
*
* const app = mount(App, { target: document.body });
*
* // later...
* unmount(app, { outro: true });
* ```
*
*/
export function unmount(component: Record<string, any>, options?: {
Expand Down

0 comments on commit d66cb51

Please sign in to comment.