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;- ✓Correct answer: The store is a reactive object;
storeToRefsturns state and getters into refs, while actions can be destructured directly - 2Pinia stores are not reactive at all
- 3Destructuring works without any helper
Explanation
Plain destructuring copies the current values. storeToRefs skips actions and non-reactive properties, so actions are taken from the store itself.