nuxt-composables

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

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "nuxt-composables" with this command: npx skills add leeovery/claude-nuxt/leeovery-claude-nuxt-nuxt-composables

Nuxt Composables

Creating reusable stateful logic via Vue Composition API.

Core Concepts

composables.md - Patterns, naming, state management, best practices

Singleton Pattern (Shared State)

State defined outside function persists across all callers:

// 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:

// 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

ConventionExample
File nameuseUser.ts, useCategories.ts
Functionexport default function useUser()
ReturnAlways object { state, methods }
RefsReactive: user, not userRef

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

nuxt-pages

No summary provided by upstream source.

Repository SourceNeeds Review
General

nuxt-architecture

No summary provided by upstream source.

Repository SourceNeeds Review
General

nuxt-config

No summary provided by upstream source.

Repository SourceNeeds Review