You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/docs/02-runes/03-$derived.md
+13-1Lines changed: 13 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,19 @@
2
2
title: $derived
3
3
---
4
4
5
-
Derived state is declared with the `$derived` rune:
5
+
6
+
Svelte's `<script>` blocks are run only when the component is created, so assignments within a `<script>` block are not automatically run again when a prop updates.
7
+
8
+
```svelte
9
+
<script>
10
+
let count = $state(0);
11
+
// this will only set `doubled` on component creation
12
+
// it will not update when `count` does
13
+
let doubled = count * 2;
14
+
</script>
15
+
```
16
+
17
+
We can make any variable based on others reactive by declaring them a Derived state using the `$derived` rune:
0 commit comments