What Makes a Good Composable
Naming convention (useName), encapsulating reactive state, returning refs not raw values.
What Is a Composable
A composable is a function that uses Vue Composition API to encapsulate and reuse stateful logic. It is the Vue 3 answer to mixins - cleaner, explicit, and type-friendly.
The use Prefix Convention
By convention composables are named with a use prefix: useCounter, useFetch, useMouse. This instantly signals that the function holds reactive logic.
function useDarkMode() { /* ... */ }
function usePagination() { /* ... */ }All lessons in this course
- What Makes a Good Composable
- useCounter: A Simple Composable
- useFetch: Async Data Composable
- VueUse: The Composable Library