Vue · Junior · Question 15 of 75

Why does destructuring a reactive object break reactivity?

const state = reactive({ count: 0 });
let { count } = state;
count++; // the UI doesn't update

Explanation

Reactivity works through property access on the Proxy. Use toRefs(state) to destructure into refs that stay connected, or use ref from the start.

Further reading

Problem with a question

Vue · Junior · question 15

Test yourself

Take the Vue · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz