Reactivity transform helps you write reactive code in Vue more simply by removing the need to write .value all the time. It makes your code cleaner and easier to read.
Reactivity transform and limitations in Vue
import { effect } from 'vue' const count = $ref(0) const state = $reactive({ name: 'Vue' }) function increment() { count++ state.name = 'Vue.js' }
Use $ref to create reactive primitive values without .value.
Use $reactive to create reactive objects with direct property access.
count directly without count.value.const count = $ref(0) count++
const state = $reactive({ name: 'Vue' }) state.name = 'Vue 3'
function greet() { console.log(`Hello, ${state.name}!`) }
This example shows how $ref and $reactive let you update reactive data directly. The effect logs changes automatically.
<script setup lang="ts"> import { effect } from 'vue' const count = $ref(0) const user = $reactive({ name: 'Alice' }) effect(() => { console.log(`Count is ${count}, user is ${user.name}`) }) function increment() { count++ user.name = 'Bob' } increment() </script>
Reactivity transform requires enabling in Vue 3.4+ with reactivityTransform: true in your config.
Not all Vue APIs support reactivity transform; some advanced cases still need .value.
Using reactivity transform can confuse beginners if mixed with normal refs, so be consistent.
Reactivity transform lets you write reactive code without .value.
Use $ref for primitives and $reactive for objects.
It simplifies code but has some limitations and requires config enabling.
Practice
Solution
Step 1: Understand Reactivity Transform purpose
Reactivity Transform lets you write reactive code without explicitly accessing.valueon refs.Step 2: Compare options
Only It allows writing reactive code without using.valueon refs. correctly states this benefit. Other options are incorrect or unrelated.Final Answer:
It allows writing reactive code without using .value on refs. -> Option AQuick Check:
Reactivity Transform = no .value needed [OK]
- Thinking it disables reactivity
- Assuming it auto-reactivates all variables
- Believing it removes all imports
Solution
Step 1: Identify correct Reactivity Transform syntax for primitives
For primitives, Reactivity Transform uses$refto declare reactive variables.Step 2: Check options
const count = $ref(0) uses$ref(0), which is correct. const count = ref(0) uses classicref, not Reactivity Transform. Options A, C, and D are incorrect for primitives.Final Answer:
const count = $ref(0) -> Option CQuick Check:
Primitive reactive = $ref() [OK]
- Using reactive() for primitives
- Confusing $reactive with $ref
- Using classic ref() instead of $ref()
import { $ref } from 'vue'
const count = $ref(1)
count++
console.log(count)What will be logged to the console?
Solution
Step 1: Understand $ref behavior
$ref creates a reactive primitive that can be used without .value. Incrementing count directly updates its value.Step 2: Trace code execution
count starts at 1, then count++ increments it to 2, so console.log(count) outputs 2.Final Answer:
2 -> Option DQuick Check:
Increment $ref count logs 2 [OK]
- Expecting .value usage
- Thinking count remains 1
- Assuming runtime error
import { $reactive } from 'vue'
const state = $reactive({ count: 0 })
state.count++
console.log(state.count)Solution
Step 1: Check Reactivity Transform usage requirements
$reactive requires enabling Reactivity Transform in Vue config before usage.Step 2: Analyze code behavior
Without enabling config, $reactive usage causes errors or unexpected behavior.Final Answer:
Reactivity Transform requires enabling in config before using $reactive. -> Option BQuick Check:
Enable config for $reactive use [OK]
- Thinking $reactive works without config
- Using .value on $reactive objects
- Believing $reactive only works with primitives
Solution
Step 1: Understand Reactivity Transform limitations on nested objects
Reactivity Transform does not automatically make deeply nested properties reactive unless wrapped with $reactive.Step 2: Evaluate options
It cannot track changes on deeply nested properties without manual $reactive wrapping. correctly states this limitation. Options B, C, and D are incorrect or false statements.Final Answer:
It cannot track changes on deeply nested properties without manual $reactive wrapping. -> Option AQuick Check:
Deep nested reactivity needs manual $reactive [OK]
- Assuming all nested properties are reactive automatically
- Using .value on nested objects
- Believing Reactivity Transform disables nested arrays
Ready to prove it?
Pass the test and this pattern moves unknown
