DEV Community

Discussion on: Thought on Vue 3 Composition API - `reactive()` considered harmful

Collapse
 
voluntadpear profile image
Guillermo Peralta Scura

Another great benefit of refs is that if you return an object where each property is a ref from a composition function, you can destructure it safely.

Collapse
 
smolinari profile image
Scott Molinari

There is a helper function for destructuring a reactive object called toRefs(). So, in the end, you can just use reactive objects and destructure them with toRefs().

Scott

Collapse
 
wormss profile image
WORMSS

Are the return types from ref().value recursive read-only?
Or are they still mutable? Are they reactive if so?

Collapse
 
voluntadpear profile image
Guillermo Peralta Scura

ref.value is mutable, and if the inner value of your ref is an object it is deeply reactive. E.g.: myObjectRef.value.bar.foo = "5" will trigger any watcher on myObjectRef

Thread Thread
 
ycmjason profile image
YCM Jason

If it is a computed ref, then I believe it will be recursively read-only.