0
0
Vueframework~20 mins

Reactive objects with reactive in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue Reactive Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Vue reactive object update?
Consider the following Vue 3 code using reactive. What will be logged to the console after the update?
Vue
import { reactive } from 'vue';

const state = reactive({ count: 0 });

console.log(state.count);
state.count = 5;
console.log(state.count);
A0 then 0
B0 then 5
Cundefined then 5
D5 then 5
Attempts:
2 left
💡 Hint
Remember that reactive objects track changes and reflect updates immediately.
📝 Syntax
intermediate
2:00remaining
Which option correctly creates a reactive nested object in Vue 3?
You want to create a reactive object with a nested property user.name. Which code snippet correctly does this?
Aconst state = reactive({ user: { name: ref('Alice') } });
Bconst state = reactive({ user: reactive({ name: 'Alice' }) });
Cconst state = reactive({ user: ref({ name: 'Alice' }) });
Dconst state = reactive({ user: { name: 'Alice' } });
Attempts:
2 left
💡 Hint
Nested objects inside reactive are automatically reactive.
🔧 Debug
advanced
2:00remaining
Why does this reactive object update not trigger reactivity?
Given this code, why does updating state.user.age not update the UI?
Vue
import { reactive } from 'vue';

const state = reactive({});

state.user = {};

// Later in code
state.user.age = 30;
ABecause <code>age</code> was not present when <code>state.user</code> was made reactive, Vue cannot track it.
BBecause <code>reactive</code> only tracks top-level properties, nested properties are ignored.
CBecause <code>state.user</code> is not reactive, only <code>state</code> is reactive.
DBecause <code>age</code> must be wrapped in <code>ref</code> to be reactive.
Attempts:
2 left
💡 Hint
Vue 3's reactivity system cannot detect new properties added after reactive creation.
state_output
advanced
2:00remaining
What is the value of state.count after this code runs?
Analyze this Vue 3 reactive code and determine the final value of state.count:
Vue
import { reactive } from 'vue';

const state = reactive({ count: 1 });

function increment() {
  state.count += 1;
}

increment();
increment();
state.count = 10;
A10
B3
C2
Dundefined
Attempts:
2 left
💡 Hint
The last assignment overwrites previous increments.
🧠 Conceptual
expert
3:00remaining
Which statement best describes Vue 3's reactive behavior with nested objects?
Select the most accurate description of how Vue 3's reactive function handles nested objects and property additions.
AVue 3's <code>reactive</code> makes nested objects reactive only if they exist at creation; new nested properties added later are not reactive.
BVue 3's <code>reactive</code> automatically tracks all nested objects and any new properties added at any time.
CVue 3's <code>reactive</code> only tracks top-level properties; nested objects must be wrapped separately with <code>reactive</code>.
DVue 3's <code>reactive</code> requires all nested properties to be wrapped with <code>ref</code> to be reactive.
Attempts:
2 left
💡 Hint
Think about Vue 3's Proxy-based reactivity and how it handles dynamic property additions.