In Svelte 5+ runes mode,
<svelte:component> is deprecated. Components are dynamic by default, so you can simply use <MyComponent> directly and it will re-render when the component value changes.<Thing>, and the value of Thing changes, nothing happens. To make it dynamic you must use <svelte:component>, which destroys and recreates the component instance when the value of its this expression changes.
Attributes
The component constructor to render. When this value changes, the component instance is destroyed and recreated.If
this is falsy, no component is rendered.Usage
Basic dynamic component
With props
You can pass props to the dynamic component like any other component:Conditional rendering
Whenthis is null or undefined, no component is rendered:
Migration to Svelte 5
In Svelte 5 runes mode, you can use components directly without<svelte:component>: