Skip to main content
InterviewHubPRO
Section Overview
Q38

Question 38 of 50

Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

76%
Vue.js & Composition API (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

Vue 3 Reactivity Caveats: Loss of Reactivity During Destructuring and How to Preserve It.

senior LevelCode ExampleSystem DesignVue & Nuxt

In Simple Words: Destructuring properties from a reactive() object strips their reactive link because JavaScript passes primitive values (number, string, boolean) by value, not by reference.

  • The Problem: Destructuring const { count } = reactive({ count: 0 }) creates an isolated primitive local variable that never updates when the store changes.
  • The Solution: Use toRefs() to wrap each key in a getter/setter ref object before destructuring.
typescript
import { reactive, toRefs } from 'vue';

const userStore = reactive({ username: 'Alex', karma: 120 });

// ❌ Anti-pattern: Reactivity lost!
const { username } = userStore;

// ✅ Optimal Pattern: Reactivity preserved!
const { username: liveUsername, karma } = toRefs(userStore);