Bird
Raised Fist0
Vueframework~20 mins

Reactivity transform and limitations in Vue - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Reactivity Transform Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
How does reactivity transform affect ref unwrapping in templates?
Consider a Vue 3 component using reactivity transform. What will be the rendered output of the template if count is a ref initialized to 5 and incremented by 1 before rendering?
Vue
<script setup lang="ts" reactivitytransform>
let count = $ref(5)
count++
</script>
<template>
  <p>{{ count }}</p>
</template>
A<p>6</p>
B<p>5</p>
C<p>[object Object]</p>
D<p>undefined</p>
Attempts:
2 left
💡 Hint
Reactivity transform unwraps refs automatically in templates.
📝 Syntax
intermediate
2:00remaining
Which code snippet correctly uses reactivity transform to create a reactive object?
Select the code that correctly creates a reactive object using Vue's reactivity transform syntax.
Alet user = reactive({ name: 'Alice', age: 30 })
Blet user = $reactive({ name: 'Alice', age: 30 })
Clet user = $ref({ name: 'Alice', age: 30 })
Dlet user = ref({ name: 'Alice', age: 30 })
Attempts:
2 left
💡 Hint
Reactivity transform provides special prefixes for reactive primitives and objects.
🔧 Debug
advanced
2:30remaining
Why does this reactivity transform code fail to track changes?
Given the code below, why does updating state.count not trigger a template update?
Vue
<script setup lang="ts" reactivitytransform>
let state = { count: $ref(0) }
function increment() {
  state.count++
}
</script>
<template>
  <p>{{ state.count }}</p>
  <button @click="increment">Increment</button>
</template>
ABecause <code>$ref</code> cannot be used inside objects with reactivity transform.
BBecause the template does not unwrap nested refs automatically.
CBecause <code>state.count++</code> syntax is invalid with reactivity transform.
DBecause <code>state</code> is a plain object, not reactive, so changes to <code>count</code> are not tracked.
Attempts:
2 left
💡 Hint
Reactivity transform requires reactive wrappers for objects to track nested properties.
🧠 Conceptual
advanced
2:00remaining
What is a key limitation of Vue's reactivity transform regarding arrays?
Which statement best describes a limitation of reactivity transform when working with arrays?
AReactivity transform does not track mutations made by direct index assignment like <code>arr[0] = value</code>.
BReactivity transform disables reactivity for array methods like <code>push</code> and <code>pop</code>.
CReactivity transform requires arrays to be wrapped with <code>$ref</code> to be reactive.
DReactivity transform cannot unwrap refs inside arrays automatically.
Attempts:
2 left
💡 Hint
Think about how Vue tracks changes to array elements.
❓ state_output
expert
2:30remaining
What is the final value of count after this reactivity transform code runs?
Analyze the code below and determine the final value of count after all statements execute.
Vue
<script setup lang="ts" reactivitytransform>
let count = $ref(1)
function update() {
  count += 2
  count = count * 3
}
update()
</script>
A6
B7
C9
D3
Attempts:
2 left
💡 Hint
Follow the arithmetic step by step.

Practice

(1/5)
1. What is the main benefit of Vue's Reactivity Transform feature?
easy
A. It allows writing reactive code without using .value on refs.
B. It automatically converts all variables to reactive objects.
C. It removes the need for any imports in Vue components.
D. It disables reactivity for better performance.

Solution

  1. Step 1: Understand Reactivity Transform purpose

    Reactivity Transform lets you write reactive code without explicitly accessing .value on refs.
  2. Step 2: Compare options

    Only It allows writing reactive code without using .value on refs. correctly states this benefit. Other options are incorrect or unrelated.
  3. Final Answer:

    It allows writing reactive code without using .value on refs. -> Option A
  4. Quick Check:

    Reactivity Transform = no .value needed [OK]
Hint: Reactivity Transform removes .value usage on refs [OK]
Common Mistakes:
  • Thinking it disables reactivity
  • Assuming it auto-reactivates all variables
  • Believing it removes all imports
2. Which syntax correctly declares a reactive primitive using Reactivity Transform in Vue?
easy
A. const count = reactive(0)
B. const count = ref(0)
C. const count = $ref(0)
D. const count = $reactive(0)

Solution

  1. Step 1: Identify correct Reactivity Transform syntax for primitives

    For primitives, Reactivity Transform uses $ref to declare reactive variables.
  2. Step 2: Check options

    const count = $ref(0) uses $ref(0), which is correct. const count = ref(0) uses classic ref, not Reactivity Transform. Options A, C, and D are incorrect for primitives.
  3. Final Answer:

    const count = $ref(0) -> Option C
  4. Quick Check:

    Primitive reactive = $ref() [OK]
Hint: Use $ref() for primitives in Reactivity Transform [OK]
Common Mistakes:
  • Using reactive() for primitives
  • Confusing $reactive with $ref
  • Using classic ref() instead of $ref()
3. Given the code:
import { $ref } from 'vue'
const count = $ref(1)
count++
console.log(count)

What will be logged to the console?
medium
A. 1
B. undefined
C. Error: count is not reactive
D. 2

Solution

  1. Step 1: Understand $ref behavior

    $ref creates a reactive primitive that can be used without .value. Incrementing count directly updates its value.
  2. Step 2: Trace code execution

    count starts at 1, then count++ increments it to 2, so console.log(count) outputs 2.
  3. Final Answer:

    2 -> Option D
  4. Quick Check:

    Increment $ref count logs 2 [OK]
Hint: Increment $ref variable directly without .value [OK]
Common Mistakes:
  • Expecting .value usage
  • Thinking count remains 1
  • Assuming runtime error
4. What is the main issue with this Vue Reactivity Transform code?
import { $reactive } from 'vue'
const state = $reactive({ count: 0 })
state.count++
console.log(state.count)
medium
A. You cannot increment properties on $reactive objects.
B. Reactivity Transform requires enabling in config before using $reactive.
C. You must use .value to access properties on $reactive objects.
D. The $reactive function only works with primitives, not objects.

Solution

  1. Step 1: Check Reactivity Transform usage requirements

    $reactive requires enabling Reactivity Transform in Vue config before usage.
  2. Step 2: Analyze code behavior

    Without enabling config, $reactive usage causes errors or unexpected behavior.
  3. Final Answer:

    Reactivity Transform requires enabling in config before using $reactive. -> Option B
  4. Quick Check:

    Enable config for $reactive use [OK]
Hint: Enable Reactivity Transform in config before using $reactive [OK]
Common Mistakes:
  • Thinking $reactive works without config
  • Using .value on $reactive objects
  • Believing $reactive only works with primitives
5. Which of the following is a limitation of Vue's Reactivity Transform when working with complex nested objects?
hard
A. It cannot track changes on deeply nested properties without manual $reactive wrapping.
B. It automatically unwraps all nested objects, causing performance issues.
C. It requires using .value for nested reactive properties.
D. It disables reactivity on nested arrays.

Solution

  1. Step 1: Understand Reactivity Transform limitations on nested objects

    Reactivity Transform does not automatically make deeply nested properties reactive unless wrapped with $reactive.
  2. 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.
  3. Final Answer:

    It cannot track changes on deeply nested properties without manual $reactive wrapping. -> Option A
  4. Quick Check:

    Deep nested reactivity needs manual $reactive [OK]
Hint: Wrap nested objects with $reactive to track changes [OK]
Common Mistakes:
  • Assuming all nested properties are reactive automatically
  • Using .value on nested objects
  • Believing Reactivity Transform disables nested arrays
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard