Complete the code to define a composable that accepts a parameter.
import { ref } from 'vue' export function useCounter(initialValue) { const count = ref([1]) function increment() { count.value++ } return { count, increment } }
The composable uses the passed initialValue parameter to set the initial count.
Complete the code to accept a parameter and return a computed value based on it.
import { computed } from 'vue' export function useGreeting(name) { const greeting = computed(() => `Hello, [1]!`) return { greeting } }
name.value which is for refsthis.name which is not valid hereThe parameter name is a plain string, so use it directly inside the template literal.
Fix the error in the composable that accepts a ref parameter and returns a reactive doubled value.
import { computed } from 'vue' export function useDouble(count) { const double = computed(() => count[1] * 2) return { double } }
.value causing runtime errorsWhen using a ref parameter, access its value with .value inside computed.
Fill both blanks to create a composable that accepts a ref and returns a computed greeting with reactive name.
import { computed } from 'vue' export function useReactiveGreeting(nameRef) { const greeting = computed(() => `Hi, [1]!`) return { greeting } }
nameRef directly which returns the ref objectnameRef() which is invalid for refsTo get the current value of a ref, use .value.
Fill all three blanks to create a composable that accepts a parameter, uses a ref, and returns a function to update it.
import { ref } from 'vue' export function useName(initialName) { const name = ref([1]) function setName(newName) { name[2] = [3] } return { name, setName } }
name instead of name.valueThe ref name is initialized with initialName. To update it, assign newName to name.value.