create-adaptable-composable

Generate Vue 3 and Nuxt 3 composables that normalize MaybeRef inputs with toValue() and toRef().

Updated Nov 3, 2024
One-click install
npx skills add https://github.com/Cancey-Dejean/vue-storybook-starter-clean --skill create-adaptable-composable-cancey-dejean
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: create-adaptable-composable
Source: https://github.com/Cancey-Dejean/vue-storybook-starter-clean/tree/main/.agents/skills/create-adaptable-composable
Command: npx skills add https://github.com/Cancey-Dejean/vue-storybook-starter-clean --skill create-adaptable-composable-cancey-dejean

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers create reusable Vue composables that can seamlessly handle both reactive and non-reactive inputs, simplifying integration into various project structures.

Core Features & Use Cases

  • Input Normalization: Automatically adapts to MaybeRef or MaybeRefOrGetter types using toValue() and toRef().
  • Predictable Reactivity: Ensures consistent behavior within reactive contexts like watch and watchEffect.
  • Use Case: Create a useDocumentTitle composable that accepts a plain string, a ref, or a getter function to dynamically set the browser tab title.

Quick Start

Create an adaptable composable named 'useResponsiveLayout' that accepts a breakpoint value.

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 refs, getters, and plain values?

You make a Vue composable accept refs, getters, and plain values by typing inputs as MaybeRef or MaybeRefOrGetter and normalizing them with toValue() or toRef(). This ensures your utility functions can seamlessly handle both reactive and non-reactive inputs for flexible integration.

What does toValue() do in a Vue 3 composable?

The toValue() function in a Vue 3 composable normalizes MaybeRefOrGetter inputs by extracting the value from refs or invoking getter functions. It ensures predictable reactivity within reactive effects like watch and watchEffect for consistent behavior.

Can I use MaybeRefOrGetter types in Nuxt 3 projects?

Yes, you can use MaybeRefOrGetter types in Nuxt 3 projects. The framework supports Vue 3 reactivity APIs, allowing you to normalize inputs with toValue() and toRef() to create reusable, flexible utility functions for your Nuxt 3 project structure.

What is the best way to handle reactive inputs in Vue utility functions?

The best way to handle reactive inputs in Vue utility functions is to accept MaybeRef or MaybeRefOrGetter types and normalize them using toRef(). This approach maintains predictable reactivity within watch and watchEffect contexts without restricting how the function is called.

Why does my Vue composable lose reactivity when passed a getter function?

A Vue composable loses reactivity when passed a getter function if it is not normalized correctly. Using toValue() within reactive effects like watchEffect ensures the getter is properly evaluated, maintaining predictable reactivity throughout the lifecycle.