Complete the code to define a named slot called "header" in a Svelte component.
<slot name="[1]"></slot>
The name attribute defines the named slot. Here, it should be "header" to create a named slot called "header".
Complete the code to fill the named slot "footer" in a parent Svelte component.
<ChildComponent> <div slot="[1]">This is the footer content.</div> </ChildComponent>
To fill a named slot, the slot attribute on the child element must match the slot's name in the child component. Here, it is "footer".
Fix the error in the code to correctly define and use a named slot "sidebar".
<!-- Child.svelte --> <slot name="[1]"></slot> <!-- Parent.svelte --> <Child> <p slot="sidebar">Sidebar content</p> </Child>
The named slot in the child component must match the slot attribute in the parent. Here, the child defines "sidebar" but the parent uses "sidebar". Changing the child's slot name to "sidebar" fixes the mismatch.
Fill both blanks to create a named slot "title" and fill it with a heading in the parent component.
<!-- Child.svelte --> <slot name="[1]">Default Title</slot> <!-- Parent.svelte --> <Child> <h1 slot="[2]">Welcome!</h1> </Child>
Both the named slot in the child and the slot attribute in the parent must be "title" to connect correctly.
Fill all three blanks to define two named slots "nav" and "content" in the child and fill them in the parent component.
<!-- Child.svelte --> <nav><slot name="[1]">Default Nav</slot></nav> <main><slot name="[2]">Default Content</slot></main> <!-- Parent.svelte --> <Child> <ul slot="[3]"> <li>Home</li> <li>About</li> </ul> <section slot="content"> <p>Main content here.</p> </section> </Child>
The child defines slots named "nav" and "content". The parent fills the "nav" slot with the
- element and the "content" slot with the
- must have slot="nav" to match the child's slot name.