toRef do in Vue's Composition API?toRef creates a reactive reference to a single property inside a reactive object. It lets you track and update that property reactively without losing reactivity.
toRefs different from toRef?toRefs converts all properties of a reactive object into separate reactive references. It helps when you want to destructure an object but keep each property reactive.
toRefs when destructuring a reactive object?Because normal destructuring breaks reactivity, toRefs keeps each property reactive by turning them into refs. This way, changes stay tracked by Vue.
toRefs?You get plain values, not reactive ones. So, Vue won't track changes to those values, and your UI won't update when they change.
toRef to create a reactive reference to a property.<pre>import { reactive, toRef } from 'vue'
const state = reactive({ count: 0 })
const countRef = toRef(state, 'count')
// Now countRef.value is reactive and linked to state.count</pre>toRefs return when used on a reactive object?toRefs returns an object where each property is a reactive reference (ref) to the original reactive object's properties.
toRefs problematic?Destructuring without toRefs extracts plain values, losing reactivity, so Vue can't track changes.
toRef creates a reactive reference to one property of a reactive object.
toRefs converts all properties to refs, preserving reactivity after destructuring.
toRef or toRefs?They keep reactivity intact when you want to destructure reactive objects.
toRef and toRefs help maintain reactivity when destructuring reactive objects in Vue.toRef instead of toRefs.