create-adaptable-composable

Normalize reactive and non-reactive inputs in Vue 3 composables with toRef() and toValue().

Updated Mar 31, 2026
One-click install
npx skills add https://github.com/aiaihome/SinotransAI --skill create-adaptable-composable-aiaihome
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: create-adaptable-composable
Source: https://github.com/aiaihome/SinotransAI/tree/main/.agents/skills/create-adaptable-composable
Command: npx skills add https://github.com/aiaihome/SinotransAI --skill create-adaptable-composable-aiaihome

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide helps developers build reusable Vue composables that gracefully accept both reactive and non-reactive inputs, simplifying API design and improving code reuse.

Core Features & Use Cases

  • Accept MaybeRef/MaybeRefOrGetter inputs and normalize them with toValue()/toRef() inside reactive effects.
  • Provide examples like useDocumentTitle (read-only) and useCounter (two-way writable) to illustrate common patterns.
  • Suitable for Vue 3 and Nuxt 3 projects to build adaptable UI logic and utilities.

Quick Start

Define a composable that accepts a MaybeRefOrGetter and uses toRef()/toValue() to normalize inputs in a reactive effect.

Frequently Asked Questions about create-adaptable-composable

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make a Vue composable accept both reactive and non-reactive inputs?

To make a Vue composable accept both reactive and non-reactive inputs, define parameters using MaybeRefOrGetter types and normalize them using toValue() or toRef() inside reactive effects. This approach allows your composable to gracefully handle plain values, refs, and getter functions.

What is MaybeRefOrGetter in Vue 3 and when do I need it?

MaybeRefOrGetter in Vue 3 is a type that allows a composable to accept a plain value, a ref, or a getter function. You need it when building adaptable API wrappers and utilities that must maintain reactivity regardless of the input format provided by the consumer.

What's the best way to normalize refs and getters inside a Vue composable?

The best way to normalize refs and getters inside a Vue composable is to use toRef() for two-way writable states and toValue() for read-only values within reactive effects. This normalizes the inputs into a consistent reactive structure for your logic.

Can I use these composable patterns for Nuxt 3 projects?

Yes, you can use these composable patterns for Nuxt 3 projects. The technique of applying MaybeRef types and normalizing inputs with toRef() and toValue() is fully compatible with Vue 3 and Nuxt 3 for building adaptable UI logic and utilities.

When should I use toValue versus toRef in a composable?

Use toValue() in a Vue composable when normalizing read-only inputs like useDocumentTitle, and use toRef() when you need a two-way writable state like useCounter. Both functions resolve MaybeRefOrGetter inputs but differ in whether they return a value or a reactive reference.