Extract composables progressively
Don't create a shared composable until you actually need to reuse it. Follow the extraction ladder:
- Inline — logic lives directly in the component's
<script setup> - Colocated file — extract to a
useFeature.tsnext to the component - Shared
composables/— promote to the shared directory only when a second consumer appears
Starting inline keeps things simple. Premature extraction adds indirection without benefit.
Example:
typescript
// Step 1: Inline in component
// <script setup>
const count = ref(0)
const increment = () => count.value++
// </script>
// Step 2: Colocated (same folder as component)
// components/Counter/useCounter.ts
export function useCounter() {
const count = ref(0)
const increment = () => count.value++
return { count, increment }
}
// Step 3: Shared (only when reused elsewhere)
// composables/useCounter.tsRule for AI agents
PREFER inline composables; extract to shared `composables/` only when a second consumer exists. Ladder: inline → colocated → shared.Eslint rule
No ESLint rule available