Skip to content

Commit 71a66dd

Browse files
authored
docs: add $state destructure example using $derived
1 parent c3348ae commit 71a66dd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

documentation/docs/02-runes/02-$state.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ let { done, text } = todos[0];
6363
todos[0].done = !todos[0].done;
6464
```
6565

66+
However, if you destructure a reactive value with `$derived`, the references will now be reactive:
67+
68+
```js
69+
let todos = [{ done: false, text: 'add more todos' }];
70+
// ---cut---
71+
let { done, text } = $derived(todos[0]);
72+
73+
// this will now affect the value of `done`
74+
todos[0].done = !todos[0].done;
75+
```
76+
6677
### Classes
6778

6879
Class instances are not proxied. Instead, you can use `$state` in class fields (whether public or private), or as the first assignment to a property immediately inside the `constructor`:

0 commit comments

Comments
 (0)