Skip to content

Commit 549826a

Browse files
authored
drive-by-fixes
1 parent 87c9632 commit 549826a

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

documentation/docs/02-runes/05-$props.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@ title: $props
55
The inputs to a component are referred to as _props_, which is short for _properties_. You pass props to components just like you pass attributes to elements:
66

77
```svelte
8+
<!--- file: App.svelte --->
89
<script>
910
import MyComponent from './MyComponent.svelte';
1011
</script>
1112
12-
/// file: App.svelte
1313
<MyComponent adjective="cool" />
1414
```
1515

1616
On the other side, inside `MyComponent.svelte`, we can receive props with the `$props` rune...
1717

1818
```svelte
19+
<!--- file: MyComponent.svelte --->
1920
<script>
2021
let props = $props();
2122
</script>
2223
23-
/// file: MyComponent.svelte
2424
<p>this component is {props.adjective}</p>
2525
```
2626

2727
...though more commonly, you'll [_destructure_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) your props:
2828

2929
```svelte
30-
/// file: MyComponent.svelte
30+
<!--- file: MyComponent.svelte --->
3131
<script>
3232
let +++{ adjective }+++ = $props();
3333
</script>
@@ -40,7 +40,6 @@ On the other side, inside `MyComponent.svelte`, we can receive props with the `$
4040
Destructuring allows us to declare fallback values, which are used if the parent component does not set a given prop:
4141

4242
```js
43-
/// file: MyComponent.svelte
4443
let { adjective = 'happy' } = $props();
4544
```
4645

@@ -66,9 +65,8 @@ let { a, b, c, ...others } = $props();
6665

6766
References to a prop inside a component update when the prop itself updates — when `count` changes in `App.svelte`, it will also change inside `Child.svelte`. But the child component is able to temporarily override the prop value, which can be useful for unsaved ephemeral state ([demo](/playground/untitled#H4sIAAAAAAAAE6WQ0WrDMAxFf0WIQR0Wmu3VTQJln7HsIfVcZubIxlbGRvC_DzuBraN92qPula50tODZWB1RPi_IX16jLALWSOOUq6P3-_ihLWftNEZ9TVeOWBNHlNhGFYznfqCBzeRdYHh6M_YVzsFNsNs3pdpGd4eBcqPVDMrNxNDBXeSRtXioDgO1zU8ataeZ2RE4Utao924RFXQ9iHXwvoPHKpW1xY4g_Bg0cSVhKS0p560Za95612ZC02ONrD8ZJYdZp_rGQ37ff_mSP86Np2TWZaNNmdcH56P4P67K66_SXoK9pG-5dF5Z9QEAAA==)):
6867

69-
<!-- prettier-ignore -->
7068
```svelte
71-
/// file: App.svelte
69+
<!--- file: App.svelte --->
7270
<script>
7371
import Child from './Child.svelte';
7472
@@ -82,9 +80,8 @@ References to a prop inside a component update when the prop itself updates —
8280
<Child {count} />
8381
```
8482

85-
<!-- prettier-ignore -->
8683
```svelte
87-
/// file: Child.svelte
84+
<!--- file: Child.svelte --->
8885
<script>
8986
let { count } = $props();
9087
</script>
@@ -97,7 +94,7 @@ References to a prop inside a component update when the prop itself updates —
9794
Prop variables are not automatically deeply reactive. What happens when mutating one of their properties depends on what the parent passed in. For example if the parent passed a non-reactive POJO as a prop, setting a property of that object in the child will not cause the component to update ([demo](/playground/untitled#H4sIAAAAAAAAE3VPS07DMBC9yshCaiuqBLYhjoQ4Q1eEReJOVIMztuJJBbJ8d-IkEqXQ5bx53yCo6VEU4kCs2eBR7EWnDXpRvAbBXy79EjDhK_PZucyf0XDC2sbjf7iyxEg82YjSq0E7rmqqWffODgwvJ22O0A22h02Wz9cq3TzVVOY_CioXrm3fUbEMQdmRuICHGCGvpiDGTxYFDyPG_Y3Cl_6_K199bpQ2yBDWBhBBwp0brPPb3Z-u7chsCSwpo9WHDNsdyApCMslzODUeyAJ23WSUsMUymyfBvYTHmmKcI2e9LyBcUmKKWyKulr_Fb2Z_SHPIAQAA)):
9895

9996
```svelte
100-
<--- file: App.svelte --->
97+
<!--- file: App.svelte --->
10198
<script>
10299
import Child from './Child.svelte';
103100
@@ -108,7 +105,7 @@ Prop variables are not automatically deeply reactive. What happens when mutating
108105
```
109106

110107
```svelte
111-
<--- file: Child.svelte --->
108+
<!--- file: Child.svelte --->
112109
<script>
113110
let { object } = $props();
114111
</script>
@@ -124,7 +121,7 @@ Prop variables are not automatically deeply reactive. What happens when mutating
124121
However if the value passed in by the parent component is itself a deeply reactive state object, then it will be deeply reactive in the child, too ([demo](/playground/untitled#H4sIAAAAAAAAE3WQwU7DMBBEf2VlITUVVQLXkERC_YaeCIfE2aoujm3FGwqy_O_YcSug0KNnx7Nv1jHVjchKtlMkSOLANmwvJFpWvjhGnybOohD0s_PZmNy-o6So9Z3F_3SuFaGiEMMqyydhqGlVS2I0eiLYHoQcYD_pEVZ5sbzOX1dPwRaMEgl0f0ROUMOdpY4wc1zPikp48OvgqorvXFWlRJe-eCiawED4QaykaUa_udHl5-rfba4mN_pETHcB9RHVTNrY7C9gPxNpBVpxKfhb7bI11A24GFIUcBJSAu9mi0AHhKUo9Cj1CUjDbIbQP1rTpjzN72t4bJX3C8kSa8vLCZLFR4q0-eogr_4LN7sC9foBAAA=)):
125122

126123
```svelte
127-
<--- file: App.svelte --->
124+
<!--- file: App.svelte --->
128125
<script>
129126
import Child from './Child.svelte';
130127
@@ -135,7 +132,7 @@ However if the value passed in by the parent component is itself a deeply reacti
135132
```
136133

137134
```svelte
138-
<--- file: Child.svelte --->
135+
<!--- file: Child.svelte --->
139136
<script>
140137
let { object } = $props();
141138
</script>
@@ -151,7 +148,7 @@ However if the value passed in by the parent component is itself a deeply reacti
151148
The fallback value of a prop not declared with `$bindable` is treated like a non-reactive POJO, and therefore also doesn't update the component when mutating its properties.
152149

153150
```svelte
154-
<--- file: Child.svelte --->
151+
<!--- file: Child.svelte --->
155152
<script>
156153
let { object = { count = 0 } } = $props();
157154
</script>

0 commit comments

Comments
 (0)