Problem Statement
What is a composable and how do you structure one?
Explanation
A composable is a plain function (usually prefixed with use*) that encapsulates reusable reactive state, watchers, and methods. It returns refs/reactive objects for consumers. Keep external effects optional and accept parameters to make it generic.
Code Solution
SolutionRead Only
export function useCounter(initial = 0){
const n = ref(initial)
const inc = (d=1)=> n.value += d
const dec = (d=1)=> n.value -= d
return { n, inc, dec }
}