Skip to main content
Unmounts a component that was previously mounted using mount() or hydrate(). Since 5.13.0, if options.outro is true, transitions will play before the component is removed from the DOM. Returns a Promise that resolves after transitions have completed if options.outro is true, or immediately otherwise.

Parameters

component
Record<string, any>
required
The component instance returned by mount() or hydrate()
options
{ outro?: boolean }
Optional configuration for unmounting
outro
boolean
default:"false"
Whether to play outro transitions before removing the component from the DOM (available since 5.13.0)

Returns

promise
Promise<void>
A promise that resolves after transitions have completed if options.outro is true, or immediately otherwise

Examples

Basic usage

With outro transitions

Conditional unmounting

Notes

  • Calling unmount() on a component that was never mounted or has already been unmounted will resolve immediately without error (in production)
  • In development mode, attempting to unmount a component twice will trigger a warning
  • If outro is true, the promise will wait for all outro transitions to complete before resolving
  • The component and all its child components will be destroyed, and cleanup functions will be called