Consider the following Svelte component usage:
<Parent> <div slot="header">Header Content</div> <div slot="footer">Footer Content</div> </Parent>
And the Parent.svelte component:
<slot name="header"/> <slot/> <slot name="footer"/>
What will be the rendered output?
<slot name="header"/> <slot/> <slot name="footer"/>
Remember that the default slot renders content without a slot attribute.
The Parent component has three slots: named 'header', default (unnamed), and named 'footer'. The usage provides content only for 'header' and 'footer' slots. The default slot is empty, so it renders nothing.
Choose the correct syntax to define a named slot called "sidebar" inside a Svelte component.
Named slots use the name attribute exactly.
The correct way to define a named slot is using <slot name="sidebar"/>. Other options use incorrect attribute names or syntax.
Given this Parent.svelte component:
<slot name="title">Default Title</slot> <slot name="content">Default Content</slot>
And this usage:
<Parent> <div slot="content">Custom Content</div> </Parent>
What will be rendered?
<slot name="title">Default Title</slot> <slot name="content">Default Content</slot>
Fallback content shows only if no slot content is provided for that slot.
The 'title' slot has no content provided, so it renders its fallback 'Default Title'. The 'content' slot has custom content, so it renders 'Custom Content'.
Consider this Parent.svelte component:
<slot name="main"/>
And this usage:
<Parent> <div slot="content">Hello</div> </Parent>
Why does "Hello" not appear in the output?
<slot name="main"/>Check if the slot names match exactly.
The slot attribute in the usage is 'content', but the Parent component expects 'main'. Because they don't match, the content is not rendered in the named slot.
Given a Svelte component with these slots:
<slot name="header"/> <slot/> <slot name="footer"/>
And usage:
<Component> <div slot="header">H</div> <div slot="footer">F</div> <div>D</div> <div slot="sidebar">S</div> </Component>
How many slots will render content?
<slot name="header"/> <slot/> <slot name="footer"/>
Only content matching slot names or default slot renders.
The 'header' slot gets 'H', the default slot gets 'D', and the 'footer' slot gets 'F'. The 'sidebar' slot is unused because no matching slot exists in the component. So 3 slots render content.