Skip to content

Commit 3fac864

Browse files
docs: add deep nesting example and explanation about reactivity of expressions
1 parent d3d95fb commit 3fac864

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

documentation/docs/01-introduction/xx-props.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,51 @@ You can specify a fallback value for a prop. It will be used if the component's
4343
4444
<Nested answer={42} /> <!-- answer is set to 42 -->
4545
<Nested answer={null} /> <!-- answer is set to null (default value is not used)-->
46-
<Nested /> <!-- answer is set to default value -->
47-
<Nested answer={undefined}/> <!-- answer is set to default value -->
46+
<Nested /> <!-- answer is set 3 (default value) -->
47+
<Nested answer={undefined}/> <!-- answer is set 3 (default value) -->
4848
4949
```
5050

51+
Deep nesting refers to having components nested within other components across multiple levels. In this setup, props can be passed from parent to child components through several layers.
52+
53+
```svelte
54+
<script>
55+
let count = 3;
56+
</script>
57+
58+
<!-- App.svelte -->
59+
<First {count} />
60+
```
61+
62+
```svelte
63+
<script>
64+
export let count;
65+
</script>
66+
67+
<!-- First.svelte -->
68+
<p>First: {count}</p>
69+
<Second {count} />
70+
```
71+
72+
```svelte
73+
<script>
74+
export let count;
75+
</script>
76+
77+
<!-- Second.svelte -->
78+
<p>Second: {count}</p>
79+
<Third {count} />
80+
```
81+
82+
```svelte
83+
<script>
84+
export let count;
85+
</script>
86+
87+
<!-- Third.svelte -->
88+
<p>Third: {count}</p>
89+
```
90+
5191
To get all properties, use rest syntax:
5292

5393
```svelte

documentation/docs/03-template-syntax/01-basic-markup.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,30 @@ A JavaScript expression can be included as text by surrounding it with curly bra
177177
{expression}
178178
```
179179

180-
When using {expression} inside markup, Svelte automatically converts the value to a string before rendering it. The conversion follows JavaScript's standard behavior:
180+
When using {expression} inside markup, Svelte automatically converts the value to a string before rendering it and makes the expression reactive (similar to wrapping it in $derived). The conversion follows JavaScript's standard behavior:
181181

182182
- Primitive values (number, boolean, string) are directly converted to strings.
183183
- Objects call their .toString() method (if not overridden, it defaults to [object Object]).
184-
- undefined and null are treated as empty strings ("").
184+
- Undefined and null are treated as empty strings ("").
185+
- Expressions using runes ($state, $derived, etc.) maintain their specific reactive behavior.
185186

186187
```svelte
187-
<script>
188+
let emptyStr = "";
188189
let num = 1;
189190
let bool = false;
190191
let obj = { key: "value" };
192+
let objToStr = obj.toString();
191193
let empty = undefined;
192-
</script>
194+
let nul = null;
195+
193196
197+
<p>{emptyStr}</p> <!-- Renders as: <p></p> -->
194198
<p>{num}</p> <!-- Renders as: <p>1</p> -->
195199
<p>{bool}</p> <!-- Renders as: <p>false</p> -->
196200
<p>{obj}</p> <!-- Renders as: <p>[object Object]</p> -->
201+
<p>{objToStr}</p> <!-- Renders as: <p>[object Object]</p> -->
197202
<p>{empty}</p> <!-- Renders as: <p></p> (empty string) -->
203+
<p>{nul}</p> <!-- Renders as: <p></p> -->
198204
```
199205

200206
Curly braces can be included in a Svelte template by using their [HTML entity](https://developer.mozilla.org/docs/Glossary/Entity) strings: `&lbrace;`, `&lcub;`, or `&#123;` for `{` and `&rbrace;`, `&rcub;`, or `&#125;` for `}`.

0 commit comments

Comments
 (0)