Vue · Middle · Question 22 of 75
How should a composable accept arguments that might be refs, getters or plain values?
export function useFetch(url: MaybeRefOrGetter<string>) {
watchEffect(() => load(toValue(url)));
}- ✓Correct answer: Type them as
MaybeRefOrGetterand normalize withtoValue()inside a reactive effect - 2Always require plain values
- 3Always require refs and read
.value
Explanation
Calling toValue inside watchEffect (or a watch getter) tracks the argument, so useFetch(() => /api/${id.value}) re-fetches when id changes.