Pulled ALL skills from 15 source repositories: - anthropics/skills: 16 (docs, design, MCP, testing) - obra/superpowers: 14 (TDD, debugging, agents, planning) - coreyhaines31/marketingskills: 25 (marketing, CRO, SEO, growth) - better-auth/skills: 5 (auth patterns) - vercel-labs/agent-skills: 5 (React, design, Vercel) - antfu/skills: 16 (Vue, Vite, Vitest, pnpm, Turborepo) - Plus 13 individual skills from various repos Mosaic Stack is not limited to coding — the Orchestrator and subagents serve coding, business, design, marketing, writing, logistics, analysis, and more. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
62 lines
2.0 KiB
Markdown
62 lines
2.0 KiB
Markdown
---
|
|
title: Always Use .value When Accessing ref() in JavaScript
|
|
impact: HIGH
|
|
impactDescription: Forgetting .value causes silent failures and bugs in reactive state updates
|
|
type: capability
|
|
tags: [vue3, reactivity, ref, composition-api]
|
|
---
|
|
|
|
# Always Use .value When Accessing ref() in JavaScript
|
|
|
|
**Impact: HIGH** - Forgetting `.value` causes silent failures where state updates don't trigger reactivity, leading to hard-to-debug issues.
|
|
|
|
When using `ref()` in Vue 3's Composition API, the reactive value is wrapped in an object and must be accessed via `.value` in JavaScript code. However, in templates, Vue automatically unwraps refs so `.value` is not needed there. This inconsistency is a common source of bugs.
|
|
|
|
## Task Checklist
|
|
|
|
- [ ] Always use `.value` when reading or writing ref values in `<script>` or `.js`/`.ts` files
|
|
- [ ] Never use `.value` in `<template>` - Vue unwraps refs automatically there
|
|
- [ ] When passing refs to functions, decide whether to pass the ref object or `.value`
|
|
- [ ] Use IDE/TypeScript to catch missing `.value` errors early
|
|
|
|
**Incorrect:**
|
|
```javascript
|
|
import { ref } from 'vue'
|
|
|
|
const count = ref(0)
|
|
|
|
// These do NOT work as expected
|
|
count++ // Tries to increment the ref object, not the value
|
|
count = 5 // Reassigns the variable, loses reactivity
|
|
console.log(count) // Logs "[object Object]", not the number
|
|
|
|
const items = ref([1, 2, 3])
|
|
items.push(4) // Error: push is not a function
|
|
```
|
|
|
|
**Correct:**
|
|
```javascript
|
|
import { ref } from 'vue'
|
|
|
|
const count = ref(0)
|
|
|
|
// Always use .value in JavaScript
|
|
count.value++ // Correctly increments to 1
|
|
count.value = 5 // Correctly sets value to 5
|
|
console.log(count.value) // Logs "5"
|
|
|
|
const items = ref([1, 2, 3])
|
|
items.value.push(4) // Correctly adds 4 to the array
|
|
```
|
|
|
|
```vue
|
|
<template>
|
|
<!-- In templates, NO .value needed - Vue unwraps automatically -->
|
|
<p>{{ count }}</p>
|
|
<button @click="count++">Increment</button>
|
|
</template>
|
|
```
|
|
|
|
## Reference
|
|
- [Vue.js Reactivity Fundamentals - ref()](https://vuejs.org/guide/essentials/reactivity-fundamentals.html#ref)
|