Challenge - 5 Problems
Reactivity Transform Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2: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>
Attempts:
2 left
💡 Hint
Reactivity transform unwraps refs automatically in templates.
✗ Incorrect
With reactivity transform, refs are unwrapped automatically in templates, so
count is treated as its inner value. Incrementing count changes the value from 5 to 6, which is displayed.📝 Syntax
intermediate2: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.
Attempts:
2 left
💡 Hint
Reactivity transform provides special prefixes for reactive primitives and objects.
✗ Incorrect
The
$reactive prefix creates a reactive object with reactivity transform. The reactive and ref functions are standard Vue APIs but not part of reactivity transform syntax.🔧 Debug
advanced2: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>
Attempts:
2 left
💡 Hint
Reactivity transform requires reactive wrappers for objects to track nested properties.
✗ Incorrect
The
state object is a plain JavaScript object. Wrapping count with $ref inside it does not make state reactive. Changes to state.count are not tracked, so the template does not update.🧠 Conceptual
advanced2: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?
Attempts:
2 left
💡 Hint
Think about how Vue tracks changes to array elements.
✗ Incorrect
Vue's reactivity system cannot detect changes made by direct index assignment on arrays (e.g.,
arr[0] = newValue). This limitation remains with reactivity transform. Instead, methods like splice or push should be used.❓ state_output
expert2: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>
Attempts:
2 left
💡 Hint
Follow the arithmetic step by step.
✗ Incorrect
Starting with
count = 1, after count += 2, count is 3. Then count = count * 3 makes it 9.