What is the difference between ref and reactive in Vue 3?
Quick Answer
ref(value) wraps any value (primitive or object) in a reactive box you access via .value. reactive(obj) makes an object deeply reactive with no .value. Common guidance: use ref for primitives and as the default; use reactive for a group of related state — but destructuring a reactive loses reactivity (use toRefs).
ref wraps a single value and you read and write it through .value in script, though the template unwraps it for you. reactive makes a whole object reactive without any .value. The catch with reactive is that if you destructure it — const { count } = state — you get a plain value and lose reactivity, so you'd use toRefs. And you can't reassign a reactive object as a whole. Because of those footguns, a lot of teams just use ref for everything and keep it consistent.
ref:const count = ref(0); count.value++. In the template you don't need.value— Vue unwraps it.reactive:const state = reactive({ count: 0 }); state.count++. Butconst { count } = stategives a plain non-reactive number.reactivecan't be reassigned wholesale (state = {...}breaks it); arefcan (obj.value = newObj).- Many teams standardise on
refeverywhere for consistency.