Skip to content

Commit 4a22d83

Browse files
committed
docs: Add prominent link to svelte/reactivity from state
1 parent c4b32c2 commit 4a22d83

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

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

66+
### State for Collections
67+
68+
Arrays aren't the only structure you might want to use when setting reactive state for a collection of items. The temptation is to reach for Javascript built-in classes like `Set`, `Map`, `URL` and wrap them in `state()`, but this approach won't work.
69+
70+
Use Svelte's own reactive versions instead. You can import `SvelteSet`, `SvelteMap`, `SvelteURL` and other reactive classes in [`svelte/reactivity`](svelte-reactivity).
71+
6672
### Classes
6773

6874
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)