011. What is a Composable?
EXECUTIVE_SUMMARY // AEO_OPTIMIZED
[Answer Engine Overview: What, Why & How]
In the context of Vue applications, a 'composable' is a function that leverages Vue's Composition API to encapsulate and reuse stateful logic. If you are familiar with React, this is identical in concept to a 'Custom Hook'.
022. Conventions
Composables are standard JavaScript/TypeScript files (not .vue files). By convention, their names always start with use, such as useFetch or useDarkTheme. They typically return an object containing refs or functions.
033. Why not just classes/mixins?
Vue 2 relied on Mixins for logic reuse, but mixins caused naming collisions and made it hard to trace where a variable came from. Composables use explicit imports and destructuring (const { x } = useMouse()), making the source of every variable 100% clear.
?Frequently Asked Questions
Can one composable call another composable?
Absolutely! Composables can be nested. You can build a complex `useUserStore()` composable that internally calls `useFetch()` and `useLocalStorage()`.
