Create and manage reactive primitive values and objects using ref and reactive
When to Use
You need reactive state in a Vue 3 component using the Composition API
Building composables that return reactive values
Managing form inputs, counters, flags, or any mutable component state
Instructions
Use ref() for primitives (strings, numbers, booleans) — access via .value.
Use reactive() for objects — access properties directly (no .value).
Use computed() for derived values that should auto-update.
Never destructure a reactive() object — it breaks reactivity. Use toRefs() if needed.
import { ref, reactive, computed, toRefs } from 'vue';
const count = ref(0); // ref for primitive
const user = reactive({ name: 'Alice', age: 30 }); // reactive for object
const greeting = computed(() => `Hello, ${user.name}!`);
count.value++; // ref needs .value
user.age = 31; // reactive — direct access
In templates, refs are auto-unwrapped — use {{ count }} not {{ count.value }}.
Use shallowRef() or shallowReactive() for large objects where deep reactivity is not needed.
Details
Vue 3's reactivity system is built on ES6 Proxy. ref() wraps a value in a reactive container with a .value property. reactive() wraps an entire object, making all properties reactive. computed() creates a cached, read-only reactive value derived from other reactive sources.
Trade-offs:
ref requires .value in JavaScript (not in templates) — a common source of bugs for new Vue developers
reactive() loses reactivity when destructured — use toRefs() to safely destructure
Deep reactivity on large objects can be expensive — use shallowRef/shallowReactive for performance
Replacing a reactive() object entirely (state = newObj) does not trigger updates — mutate properties instead
When NOT to use:
For non-reactive constants — just use const without wrapping
For data that never changes after initialization — no need for reactivity overhead
For large datasets rendered in lists — consider shallowRef with manual trigger via triggerRef()
Read the instructions and examples in this document.
Apply the patterns to your implementation, adapting to your specific context.
Verify your implementation against the details and edge cases listed above.
Harness Integration
Type: knowledge — this skill is a reference document, not a procedural workflow.
No tools or state — consumed as context by other skills and agents.
Success Criteria
The patterns described in this document are applied correctly in the implementation.
Edge cases and anti-patterns listed in this document are avoided.
1---2name: vue-reactive-refs3description: Vue Reactive Refs4---5# Vue Reactive Refs67> Create and manage reactive primitive values and objects using ref and reactive89## When to Use1011- You need reactive state in a Vue 3 component using the Composition API12- Building composables that return reactive values13- Managing form inputs, counters, flags, or any mutable component state1415## Instructions16171. Use `ref()` for primitives (strings, numbers, booleans) — access via `.value`.182. Use `reactive()` for objects — access properties directly (no `.value`).193. Use `computed()` for derived values that should auto-update.204. Never destructure a `reactive()` object — it breaks reactivity. Use `toRefs()` if needed.2122```typescript23import { ref, reactive, computed, toRefs } from 'vue';2425const count = ref(0); // ref for primitive26const user = reactive({ name: 'Alice', age: 30 }); // reactive for object27const greeting = computed(() => `Hello, ${user.name}!`);2829count.value++; // ref needs .value30user.age = 31; // reactive — direct access31```32335. In templates, refs are auto-unwrapped — use `{{ count }}` not `{{ count.value }}`.346. Use `shallowRef()` or `shallowReactive()` for large objects where deep reactivity is not needed.3536## Details3738Vue 3's reactivity system is built on ES6 Proxy. `ref()` wraps a value in a reactive container with a `.value` property. `reactive()` wraps an entire object, making all properties reactive. `computed()` creates a cached, read-only reactive value derived from other reactive sources.3940**Trade-offs:**4142- `ref` requires `.value` in JavaScript (not in templates) — a common source of bugs for new Vue developers43- `reactive()` loses reactivity when destructured — use `toRefs()` to safely destructure44- Deep reactivity on large objects can be expensive — use `shallowRef`/`shallowReactive` for performance45- Replacing a `reactive()` object entirely (`state = newObj`) does not trigger updates — mutate properties instead4647**When NOT to use:**4849- For non-reactive constants — just use `const` without wrapping50- For data that never changes after initialization — no need for reactivity overhead51- For large datasets rendered in lists — consider `shallowRef` with manual trigger via `triggerRef()`5253## Source5455https://patterns.dev/vue/reactive-refs5657## Process58591. Read the instructions and examples in this document.602. Apply the patterns to your implementation, adapting to your specific context.613. Verify your implementation against the details and edge cases listed above.6263## Harness Integration6465- **Type:** knowledge — this skill is a reference document, not a procedural workflow.66- **No tools or state** — consumed as context by other skills and agents.6768## Success Criteria6970- The patterns described in this document are applied correctly in the implementation.71- Edge cases and anti-patterns listed in this document are avoided.
Run npx skillmds@latest add intense-visions/vue-reactive-refs in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Vue Reactive Refs It is listed under Web & Frontend on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Intense-Visions (@intense-visions) published this skill. Their other Agent Skills are listed on their SkillMD profile.