Content-Length: 276181 | pFad | http://github.com/sveltejs/svelte/pull/16306/commits/71a66dda01d1d3651c9feecbb57c2c0706ded959

A3 docs: add $state destructure example using $derived by anthumchris · Pull Request #16306 · sveltejs/svelte · GitHub
Skip to content

docs: add $state destructure example using $derived #16306

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
docs: add $state destructure example using $derived
  • Loading branch information
anthumchris authored Jul 5, 2025
commit 71a66dda01d1d3651c9feecbb57c2c0706ded959
11 changes: 11 additions & 0 deletions documentation/docs/02-runes/02-$state.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ let { done, text } = todos[0];
todos[0].done = !todos[0].done;
```

However, if you destructure a reactive value with `$derived`, the references will now be reactive:

```js
let todos = [{ done: false, text: 'add more todos' }];
// ---cut---
let { done, text } = $derived(todos[0]);

// this will now affect the value of `done`
todos[0].done = !todos[0].done;
```

### Classes

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`:
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/sveltejs/svelte/pull/16306/commits/71a66dda01d1d3651c9feecbb57c2c0706ded959

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy