# Nuxt Composables

> Creating custom Vue composables with proper patterns. Use when building reusable stateful logic, shared state management, or encapsulating feature-specific behavior.

- Skill: `leeovery/nuxt-composables` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx skillmds@latest add leeovery/nuxt-composables`
- Raw SKILL.md: https://api.skillmd.com/api/skills/leeovery/nuxt-composables/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- Author: leeovery (https://skillmd.com/u/leeovery)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/leeovery/nuxt-composables

---


# Nuxt Composables

Creating reusable stateful logic via Vue Composition API.

## Core Concepts

**[composables.md](references/composables.md)** - Patterns, naming, state management, best practices

**[multi-step-state.md](references/multi-step-state.md)** - SSR-safe shared state across routes via `useState`, deriving step from `route.path`, submit-with-side-effects, why caller owns `loading`

## Singleton Pattern (Shared State)

State defined outside function persists across all callers:

```typescript
// app/composables/useUser.ts
let user = ref<User>()  // Singleton - shared across app

export default function useUser() {
  const setUser = (data: BaseEntity) => {
    user.value = User.hydrate(data)
  }
  const clearUser = () => { user.value = undefined }

  return { user, setUser, clearUser }
}
```

## Factory Pattern (Fresh State)

State defined inside function - new instance per call:

```typescript
// app/composables/useCounter.ts
export default function useCounter(initial = 0) {
  const count = ref(initial)  // Fresh per call
  const increment = () => count.value++
  const decrement = () => count.value--

  return { count, increment, decrement }
}
```

## Naming & File Conventions

| Convention | Example |
|------------|---------|
| File name | `useUser.ts`, `useCategories.ts` |
| Function | `export default function useUser()` |
| Return | Always object `{ state, methods }` |
| Refs | Reactive: `user`, not `userRef` |

