0
0
Vueframework~20 mins

Why advanced reactivity matters in Vue - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue Reactivity Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What will this Vue component display after clicking the button twice?

Consider this Vue 3 component using the Composition API. What will be the displayed count after clicking the button two times?

Vue
<template>
  <button @click="increment">Click me</button>
  <p>Count: {{ count }}</p>
</template>

<script setup>
import { ref } from 'vue'
const count = ref(0)
function increment() {
  count.value++
}
</script>
ACount: 0
BCount: 1
CCount: 2
DCount: undefined
Attempts:
2 left
💡 Hint

Remember that ref creates a reactive value that updates the UI when changed.

state_output
intermediate
2:00remaining
What is the output of this reactive object update?

Given this Vue 3 code snippet, what will be the value of state.message after calling updateMessage()?

Vue
<script setup>
import { reactive } from 'vue'
const state = reactive({ message: 'Hello' })
function updateMessage() {
  state.message = 'Hi'
}
updateMessage()
</script>
A'Hi'
B'Hello'
Cundefined
Dnull
Attempts:
2 left
💡 Hint

Reactive objects update their properties reactively when assigned new values.

🔧 Debug
advanced
2:00remaining
Why does this Vue shallowReactive array update not trigger the UI update?

Look at this Vue 3 code snippet. The UI does not update after pushing a new item to the array. Why?

Vue
<script setup>
import { shallowReactive } from 'vue'
const state = shallowReactive({ items: [] })
function addItem() {
  state.items.push('new')
}
addItem()
</script>
ABecause the array was not declared with ref()
BBecause the function addItem was not called inside a lifecycle hook
CBecause push returns the new length, not the array
DBecause shallowReactive does not track array mutations like push
Attempts:
2 left
💡 Hint

Think about shallowReactive vs reactive and how Vue tracks changes in nested arrays.

🧠 Conceptual
advanced
2:00remaining
What is the main benefit of Vue 3's Proxy-based reactivity over Vue 2's Object.defineProperty?

Vue 3 uses Proxy for reactivity instead of Object.defineProperty like Vue 2. What is the main advantage of this change?

AIt allows tracking of property additions and deletions dynamically
BIt improves performance by avoiding all reactivity tracking
CIt makes Vue components run without a virtual DOM
DIt removes the need for any reactive declarations in code
Attempts:
2 left
💡 Hint

Think about what Proxy can do that Object.defineProperty cannot.

📝 Syntax
expert
2:00remaining
Which option correctly creates a computed property that doubles a reactive count in Vue 3?

Choose the correct Vue 3 Composition API syntax to create a computed property doubleCount that returns count * 2, where count is a ref.

Aconst doubleCount = computed(count * 2)
Bconst doubleCount = computed(() => count.value * 2)
Cconst doubleCount = computed(() => count * 2)
Dconst doubleCount = computed(() => { return count * 2 })
Attempts:
2 left
💡 Hint

Remember to access the value inside a ref with .value.