Vue · Middle · Question 38 of 75

Why does destructuring a Pinia store lose reactivity, and how is it fixed?

const store = useCartStore();
const { items, total } = storeToRefs(store);
const { addItem } = store;

Explanation

Plain destructuring copies the current values. storeToRefs skips actions and non-reactive properties, so actions are taken from the store itself.

Further reading

Problem with a question

Vue · Middle · question 38

Test yourself

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

Take this quiz