Skip to content

Commit 3e86657

Browse files
clarify let: directives
1 parent 9425f18 commit 3e86657

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

site/content/docs/03-template-syntax.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,22 +1600,26 @@ Note that explicitly passing in an empty named slot will add that slot's name to
16001600

16011601
---
16021602

1603-
Slots can be rendered zero or more times and can pass values *back* to the parent using props. The parent exposes the values to the slot template using the `let:` directive.
1603+
Slots can be rendered zero or more times.
16041604

1605+
The `let:` directive gives a slot template access to variables defined in the component that uses them.
16051606
The usual shorthand rules apply — `let:item` is equivalent to `let:item={item}`, and `<slot {item}>` is equivalent to `<slot item={item}>`.
16061607

16071608
```sv
16081609
<!-- FancyList.svelte -->
1610+
<!-- This component passes data to its child slot using the `itemData` prop -->
16091611
<ul>
16101612
{#each items as item}
16111613
<li class="fancy">
1612-
<slot prop={item}></slot>
1614+
<slot itemData={item}></slot>
16131615
</li>
16141616
{/each}
16151617
</ul>
16161618
16171619
<!-- App.svelte -->
1618-
<FancyList {items} let:prop={thing}>
1620+
<!-- the `let:itemData={thing}` directive makes the value that `FancyList` pases as the `itemData` prop
1621+
available to the slot template as the `thing` variable -->
1622+
<FancyList {items} let:itemData={thing}>
16191623
<div>{thing.text}</div>
16201624
</FancyList>
16211625
```

0 commit comments

Comments
 (0)