About
Projects
BlogWhere I write, think and learn.GallerySometimes I also take photos.WrappedA recap of what's been on rotation lately.
Blog
Gallery
Wrapped
© 2026 /Gilang Fatahilah

← Notebook · Entry No.02 · December 5, 2025 · 5 min read

Ref vs Reactive, which one should you use?

A practical explanation of the differences between ref and reactive in Vue 3, complete with code examples, common pitfalls, and best practices for their use.

filed under Vue, Javascript, Front-end

Ref vs Reactive, which one should you use?
Pass this page on

Introduction

In Vue 3 with the Composition API, we often use ref() and reactive() to create reactive state. Although they look similar at first glance, they actually have important differences in how they are used and how they behave. This article will discuss:
  • The difference between the concepts of ref() and reactive()
  • When to use each one
  • Real code examples
  • Common pitfalls

What is ref ?

ref() is used to create a single reactive variable. Key features of ref():
  • Works with primitives e.g string, number, boolean and object.
  • Auto-unwrapping in templates
  • Returns an object with a .value property
Even though ref() requires .value in JavaScript, Vue automatically unwraps it inside the template, so you can use it directly without .value.

Ref example

Keep in mind that ref is a reactive variable, so any change in value will trigger a re-render of the component.

When should you use ref ?

ref() is best suited for:
  • Single counter
  • Toggle states
  • Loading indicators
  • Single form input

What is reactive ?

reactive() is used to create a reactive object variable. Instead of wrapping a single value like ref(), it makes the entire object reactive. Key features of reactive():
  • Only works with object e.g object, array, Map, Set
  • Direct property access without .value
  • Ideal for complex structured state like forms and nested data
  • Uses Vue's Proxy-based reactivity system
Unlike ref(), you can access and mutate properties of a reactive() object just like a normal JavaScript object.

Reactive example

Here, form behaves like a normal object, but every property inside it is fully reactive.

When should you use reactive ?

reactive() is best suited for:
  • Form data (login, register, profile, etc.)
  • API response objects
  • Global or shared state (small scale)
  • Nested objects and arrays

Common pitfalls

Destructuring reactive objects

When you destructure a reactive() object, you lose reactivity because the properties are no longer linked to the original reactive object. Why this happens is because destructuring breaks the connection to the Vue's proxy. Instead, use toRefs() to maintain reactivity when destructuring.

Forgetting .value when using ref

Correct : This mistake happens very often when switching between template and script logic.

Using ref for large objects

This technically works, but accessing via : becomes cumbersome for larger objects. In such cases, prefer using reactive() for better readability and maintainability. Better approach :

Conclusion

Here is a quick side-by-side comparison between ref() and reactive() to make the differences clearer:
Feature
ref
reactive
Data typePrimitive & ObjectObject only
Access in javascript.value requiredDirect property access
Access in templateAuto-unwrappedNormal object access
Best forSingle valuesComplex structured state
Common usageCounters, toggles, loading statesForms, API responses, nested data
Destructuring safe?YesNo (use toRefs())
This table alone already answers most beginner confusion about when to use each one. I normally use ref() as I find it more flexible.
Gilang Fatahilah

— Gilang

Thanks for reading this far. Come back whenever there's a new page.

Share this entry:

Keep reading

  1. Entry No.03December 7, 2025Vue, Javascript, Front-end

    Avoiding Props Drilling in Vue.js: 4 Effective Solutions You Need to Know

    Props drilling often becomes an issue as Vue 3 applications grow larger. This article discusses 4 effective solutions to avoid props drilling with real-world examples using the Composition API.

    5 min read →
  2. Entry No.05January 25, 2026Personal Thoughts, Linux

    I'm Switching to Linux: Was Fedora the Right Choice?

    After one month of switching from Windows to Fedora Linux, I share my honest experience as a developer. From better performance and a cleaner workflow to Docker, GNOME, and daily dev tools, this article explores whether Fedora is really the right choice, and the trade-offs that come with it.

    4 min read →
app.vue
<script setup>
import { ref } from "vue";

const count = ref(0);
const username = ref("");
const isOpen = ref(false);

const increment = () => {
count.value++; // Accessing the value using .value
}

</script>

<template>
<p>count = {{ count }}</p>
<button @click="increment">Increment</button>
</template>
app.vue
<script setup>
import { reactive } from "vue";

const form = reactive({
email: "",
password: "",
});

const submit = () => {
console.log(form.email, form.password); // Access properties directly without .value
}
</script>

<template>
<input v-model="form.email" placeholder="Email" />
<input v-model="form.password" type="password" placeholder="Password" />

<button @click="submit">Login</button>
</template>
app.vue
const state = reactive({
count: 0,
});

const { count } = state; // reactivity is lost
app.vue
import { toRefs } from "vue";

const state = reactive({
count: 0,
});

const { count } = toRefs(state); // still reactive
app.vue
const count = ref(0);

count++; // this will not work
app.vue
count.value++;
app.vue
const form = ref({
name: "",
email: "",
password: "",
});
app.vue
form.value.name
app.vue
const form = reactive({
name: "",
email: "",
password: "",
});