Vue3 Fundamentals · Reactivity

ref or reactive?

choosing between ref and reactive

ref or reactive?

ref and reactive both make state reactive, and both re-render the component when the state changes. The difference is shape.

ref wraps a single value — a number, a string, an object. You reach the value through .value in JavaScript, and Vue unwraps it in the template:

const count = ref(0);
count.value += 1;

reactive wraps an object and tracks each property. You read and write the properties directly, with no .value:

const state = reactive({ count: 0, name: 'Vue' });
state.count += 1;

Two practical rules follow. First, reactive only works on objects: pass it a number and it cannot track anything, so use ref for primitives. Second, a reactive object cannot be reassigned wholesale — state = { ... } drops the proxy and the link. A ref can: count.value = newObject stays reactive.

When in doubt, reach for ref. It works for every value, it survives reassignment, and it is the form you pass around and destructure. Choose reactive when a group of properties genuinely belongs together and you want to read them without .value.

You are about to answer a short quiz on choosing between the two.

  1. A `ref` holds a single value and exposes it through `.value` in JavaScript.
  2. `reactive` can wrap a primitive such as a number.
  3. To read a `ref`'s value inside a `<script setup>` block, you access its ___ property.
  4. Reassigning a `reactive` object (`state = { ... }`) keeps it reactive.
  5. When a group of properties belongs together and you want to read them without `.value`, use ___.