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();

Explanation

toRef(state, 'x') does it for one property. Returning refs from composables is the convention precisely so consumers can destructure.

Further reading

Problem with a question

Vue · Middle · question 6

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