Skip to content

Commit b5fed42

Browse files
committed
make handler async, move into script block
1 parent 64e33e8 commit b5fed42

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

documentation/docs/02-runes/03-$derived.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,8 @@ Derived expressions are recalculated when their dependencies change, but you can
6161
let { post, like } = $props();
6262
6363
let likes = $derived(post.likes);
64-
</script>
6564
66-
<button
67-
onclick={() => {
65+
async function onclick() {
6866
// increment the `likes` count immediately...
6967
likes += 1;
7068
@@ -75,10 +73,10 @@ Derived expressions are recalculated when their dependencies change, but you can
7573
// failed! roll back the change
7674
likes -= 1;
7775
}
78-
}}
79-
>
80-
🧡 {likes}
81-
</button>
76+
}
77+
</script>
78+
79+
<button {onclick}>🧡 {likes}</button>
8280
```
8381

8482
> [!NOTE] Prior to Svelte 5.25, deriveds were read-only.

0 commit comments

Comments
 (0)