Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Remove callback prop example from 02-runes.md #10740

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 0 additions & 27 deletions sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md
Expand Up @@ -312,33 +312,6 @@ This also applies to more complex calculations that require more than a simple e
</script>
```

When reacting to a state change and writing to a different state as a result, think about if it's possible to use callback props instead.

```svelte
<!-- Don't do this -->
<script>
let value = $state();
let value_uppercase = $state();
$effect(() => {
value_uppercase = value.toUpperCase();
});
</script>

<Text bind:value />

<!-- Do this instead: -->
<script>
let value = $state();
let value_uppercase = $state();
function onValueChange(new_text) {
value = new_text;
value_uppercase = new_text.toUpperCase();
}
</script>

<Text {value} {onValueChange}>
```

If you want to have something update from above but also modify it from below (i.e. you want some kind of "writable `$derived`"), and events aren't an option, you can also use an object with getters and setters.

```svelte
Expand Down