Skip to content

Mention unwrapping of refs for readonly and shallow proxies #840

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

Merged
Merged
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
17 changes: 17 additions & 0 deletions src/api/basic-reactivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ original.count++
copy.count++ // warning!
```

As with [`reactive`](#reactive), if any property uses a `ref` it will be automatically unwrapped when it is accessed via the proxy:

```js
const raw = {
count: ref(123)
}

const copy = readonly(raw)

console.log(raw.count.value) // 123
console.log(copy.count) // 123
```

## `isProxy`

Checks if an object is a proxy created by [`reactive`](#reactive) or [`readonly`](#readonly).
Expand Down Expand Up @@ -191,6 +204,8 @@ isReactive(state.nested) // false
state.nested.bar++ // non-reactive
```

Unlike [`reactive`](#reactive), any property that uses a [`ref`](/api/refs-api.html#ref) will **not** be automatically unwrapped by the proxy.

## `shallowReadonly`

Creates a proxy that makes its own properties readonly, but does not perform deep readonly conversion of nested objects (exposes raw values).
Expand All @@ -209,3 +224,5 @@ state.foo++
isReadonly(state.nested) // false
state.nested.bar++ // works
```

Unlike [`readonly`](#readonly), any property that uses a [`ref`](/api/refs-api.html#ref) will **not** be automatically unwrapped by the proxy.