Composable
ELI5 — The Vibe Check
Composables are Vue's version of React hooks — reusable functions that bundle reactive state and logic together. Instead of copying the same fetch logic into 10 components, you write one useFetch composable and share it everywhere. Work smarter, not harder.
Real Talk
Composables are functions in Vue's Composition API that encapsulate and reuse stateful logic. They leverage Vue's reactivity system (ref, computed, watch) and lifecycle hooks. By convention they start with 'use'. Equivalent to React's custom hooks.
Show Me The Code
// composables/useFetch.js
import { ref } from 'vue';
export function useFetch(url) {
const data = ref(null);
const loading = ref(true);
fetch(url)
.then(r => r.json())
.then(d => { data.value = d; loading.value = false; });
return { data, loading };
}
When You'll Hear This
"Extract the auth logic into a useAuth composable." / "Composables are the Composition API equivalent of mixins but without the naming collision hell."
Related Terms
Hook
Hooks are special functions in React that let function components use superpowers like state and lifecycle that used to be class-only.
Reactive
Reactive means your data and your UI are connected — when the data changes, the screen updates automatically, like magic.
Reactivity
Reactivity is the system that makes your UI automatically keep up with your data.
State
State is a component's memory — data that can change over time and causes the UI to update when it does. Think of a counter: the number is state.
Vue
Vue is a JavaScript framework for building interactive UIs. It's famous for being easy to pick up — HTML developers feel right at home.