Skip to content
Open
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
18 changes: 16 additions & 2 deletions documentation/docs/02-runes/02-$state.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ import { count } from './state.svelte.js';
console.log(typeof count); // 'object', not 'number'
```

This leaves you with two options for sharing state between modules — either don't reassign it...
This leaves you with three options for sharing state between modules — either don't reassign it...

```js
// This is allowed — since we're updating
Expand All @@ -334,7 +334,7 @@ export function increment() {
}
```

...or don't directly export it:
...don't directly export it:

```js
let count = $state(0);
Expand All @@ -347,3 +347,17 @@ export function increment() {
count += 1;
}
```

...or wrap your state in an instance of a class:

```js
class CountStore {
count = $state(0);
}

export let countStore = new CountStore();

export function increment() {
countStore.count += 1;
}
```
Loading