Complete the code to create a reactive count variable inside a composable.
import { [1] } from 'vue'; export function useCounter() { const count = [1](0); return { count }; }
We use ref to create a reactive primitive value like a number.
Complete the code to define a function that increments the count in the composable.
import { ref } from 'vue'; export function useCounter() { const count = ref(0); function increment() { count[1]++; } return { count, increment }; }
To change the value inside a ref, we use .value.
Fix the error in the composable by completing the code to return reactive state correctly.
import { ref } from 'vue'; export function useCounter() { const count = ref(0); return [1]; }
The composable should return an object with the reactive properties so they can be used by components.
Fill both blanks to create a composable that doubles the count reactively using a computed property.
import { ref, [1] } from 'vue'; export function useCounter() { const count = ref(0); const double = [2](() => count.value * 2); return { count, double }; }
We import and use computed to create a reactive value based on count.
Fill all three blanks to create a composable that tracks count, increments it, and resets it to zero.
import { [1] } from 'vue'; export function useCounter() { const count = [2](0); function increment() { count.value++; } function reset() { count.value = [3]; } return { count, increment, reset }; }
We use ref to create the reactive count, and reset sets it back to zero.