Skip to content
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

Add a remark about watching objects/array refs #2454

Open
silentmantra opened this issue Jul 28, 2023 · 1 comment
Open

Add a remark about watching objects/array refs #2454

silentmantra opened this issue Jul 28, 2023 · 1 comment

Comments

@silentmantra
Copy link

silentmantra commented Jul 28, 2023

From the docs at least for me it's not obvious that watching a ref is actually shallow watching its value only.
The problem that we know that an object/array ref makes the object/array accessed through the ref's value reactive.
So intuitively it could seem that watching an object/array ref is deep like watching a reactive variable, but it's not.

I think a remark about this case should be added in the docs, otherwise I see periodically that kind of questions on the stackoverflow:

https://stackoverflow.com/questions/76786334/cannot-watch-an-array-ref-in-vue-3/76786671

@alexchexes
Copy link

Absolutely. There is inconsistent terminology usage. The deep watchers section states the following:

When you call watch() directly on a reactive object, it will implicitly create a deep watcher.

At the same time, the ref() documentation section states:

ref()
Takes an inner value and returns a reactive and mutable ref object.

But actually, when you call watch() on ref (which is a reactive object according to the ref() documentation), it will not create a deep watcher.

So this needs to be clarified, as the current phrasing is misleading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants