Vue.js Medium technical 0 views 1 min read

What is the difference between ref and reactive, and what are the pitfalls?

Peer-reviewed by HireXTech Technical Panel • Updated for 2025/2026 hiring • Editorial standards
Practise this track
Interviewer Expectations for this Question
01
Core Competency

Assesses fundamental understanding of Vue.js conventions, runtime behavior, and memory/performance considerations.

02
Evaluation Criteria

Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.

Comprehensive Model Answer Verified Solution

ref creates a reactive reference that can hold any value, including primitives, and is accessed through .value in JavaScript while auto-unwrapping in templates. reactive returns a Proxy for an object and lets you access properties directly, but it only works with objects, arrays and collections, and it cannot be reassigned without losing reactivity.

const n = ref(0); n.value++;
const state = reactive({ count: 0 }); state.count++;

Pitfalls: destructuring a reactive object loses reactivity because you extract a raw value, so use toRefs or storeToRefs with Pinia. Replacing the whole reactive object (state = {...}) breaks the proxy, whereas n.value = {...} is fine.

ref is generally the recommended default because it is composable, works for primitives, and can be passed around without losing the link. reactive is convenient for grouped state. readonly and shallowRef are useful variants when you want to prevent mutation or skip deep conversion.

Candidate Response Strategy & Interview Tips

  1. Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
  2. Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
  3. Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
  4. Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.
Related Topics & Skills
Spotted an error or have an alternative solution?