Skip to content

Commit

Permalink
watch example
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Oct 17, 2023
1 parent b82af16 commit 39dabf0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions docs/guides/computed-properties.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const greetings = proxy({
```

Another method would be to create a separate proxy and
synchronize with `subscribe` or `watch`.
synchronize with `subscribe`.

```js
const user = proxy({
Expand All @@ -111,11 +111,23 @@ const user = proxy({
const greetings = proxy({
greetingEn: 'Hello ' + user.name,
})
const unsub = subscribe(user, () => {
subscribe(user, () => {
greetings.greetingEn = 'Hello ' + user.name
})
```

Or with `watch`.

```js
const user = proxy({
name: 'John',
})
const greetings = proxy({})
watch((get) => {
greetings.greetingEn = 'Hello ' + get(user).name
})
```

## Object getter and setter

Setters are also supported:
Expand Down

0 comments on commit 39dabf0

Please sign in to comment.