create-adaptable-composable

Originally fromvuejs-ai/skills
Installation
Summary

Library-grade Vue composables that accept plain values, refs, or getters as inputs.

  • Use MaybeRefOrGetter for read-only inputs (computed-friendly) and MaybeRef for writable two-way inputs; normalize with toRef() for reactive sources and toValue() for non-reactive values
  • Avoid MaybeRefOrGetter when parameters are callbacks or predicates to prevent accidental function invocation
  • Requires Vue 3 or Nuxt 3; follow the four-step design pattern: confirm API, identify reactive params, normalize inputs in effects, implement core logic
SKILL.md

Create Adaptable Composable

Adaptable composables are reusable functions that can accept both reactive and non-reactive inputs. This allows developers to use the composable in a variety of contexts without worrying about the reactivity of the inputs.

Steps to design an adaptable composable in Vue.js:

  1. Confirm the composable's purpose and API design and expected inputs/outputs.
  2. Identify inputs params that should be reactive (MaybeRef / MaybeRefOrGetter).
  3. Use toValue() or toRef() to normalize inputs inside reactive effects.
  4. Implement the core logic of the composable using Vue's reactivity APIs.

Core Type Concepts

Type Utilities

/**
 * value or writable ref (value/ref/shallowRef/writable computed)
 */
export type MaybeRef<T = any> = T | Ref<T> | ShallowRef<T> | WritableComputedRef<T>;
Related skills
Installs
1.7K
Repository
hyf0/vue-skills
GitHub Stars
2.4K
First Seen
Jan 28, 2026