What is the difference between ref and reactive, and what are the pitfalls?
Assesses fundamental understanding of Vue.js conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
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
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.