Vue · Middle · Question 6 of 75
What does toRefs do?
function useMouse() {
const state = reactive({ x: 0, y: 0 });
return toRefs(state);
}
const { x, y } = useMouse();- ✓Correct answer: Converts each property of a reactive object into a ref linked to the original, so destructuring stays reactive
- 2Creates a deep copy of the object
- 3Makes the object read-only
Explanation
toRef(state, 'x') does it for one property. Returning refs from composables is the convention precisely so consumers can destructure.