From 53a2c49a478c23de71ed33f8728570a49d79934d Mon Sep 17 00:00:00 2001
From: Rich-Harris <1162160+Rich-Harris@users.noreply.github.com>
Date: Thu, 31 Oct 2024 18:53:38 +0000
Subject: [PATCH] sync svelte docs
---
.../content/docs/svelte/02-runes/05-$props.md | 89 +++++++++++++++++--
.../svelte/03-template-syntax/05-await.md | 9 ++
.../svelte/07-misc/07-v5-migration-guide.md | 2 +-
3 files changed, 90 insertions(+), 10 deletions(-)
diff --git a/apps/svelte.dev/content/docs/svelte/02-runes/05-$props.md b/apps/svelte.dev/content/docs/svelte/02-runes/05-$props.md
index 8e3dcfb341..58e9b36f8e 100644
--- a/apps/svelte.dev/content/docs/svelte/02-runes/05-$props.md
+++ b/apps/svelte.dev/content/docs/svelte/02-runes/05-$props.md
@@ -5,29 +5,29 @@ title: $props
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:
```svelte
+
-/// file: App.svelte
this component is {props.adjective}
``` ...though more commonly, you'll [_destructure_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) your props: ```svelte -/// file: MyComponent.svelte + @@ -40,11 +40,10 @@ On the other side, inside `MyComponent.svelte`, we can receive props with the `$ Destructuring allows us to declare fallback values, which are used if the parent component does not set a given prop: ```js -/// file: MyComponent.svelte let { adjective = 'happy' } = $props(); ``` -> [!NOTE] Fallback values are not turned into reactive state proxies. +> [!NOTE] Fallback values are not turned into reactive state proxies (see [Updating props](#Updating-props) for more info) ## Renaming props @@ -66,9 +65,8 @@ let { a, b, c, ...others } = $props(); 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==)): - ```svelte -/// file: App.svelte + @@ -94,6 +91,80 @@ References to a prop inside a component update when the prop itself updates — ``` +While you can temporarily _reassign_ props, you should not _mutate_ props unless they are [bindable]($bindable). + +If the prop is a regular object, the mutation will have no effect ([demo](/playground/untitled#H4sIAAAAAAAAE3WQwU7DMBBEf2W1QmorQgJXk0RC3PkBwiExG9WQrC17U4Es_ztKUkQp9OjxzM7bjcjtSKjwyfKNp1aLORA4b13ADHszUED1HFE-3eyaBcy-Mw_O5eFAg8xa1wb6T9eWhVgCKiyD9sZJ3XAjZnTWCzzuzfAKvbcjbPJieR2jm_uGy-InweXqtd0baaliBG0nFgW3kBIUNWYo9CGoxE-UsgvIpw2_oc9-LmAPJBCPDJCggqvlVtvdH9puErEMlvVg9HsVtzuoaojzkKKAfRuALVDfk5ZZW0fmy05wXcFdwyktlUs-KIinljTXrRVnm7-kL9dYLVbUAQAA)): + +```svelte + + + +The error is {error}
{/await} ``` + +> [!NOTE] You can use `#await` with [`import(...)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) to render components lazily: +> +> ```svelte +> {#await import('./Component.svelte') then { default: Component }} +>