0
0
Vueframework~20 mins

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

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 happens when you directly assign a new property to a reactive object?

Consider a reactive object created with reactive(). What will happen if you add a new property directly after creation?

Vue
import { reactive } from 'vue';
const state = reactive({ count: 0 });
state.newProp = 123;
console.log(state.newProp);
AThe new property is added but is not reactive; changes won't trigger updates.
BThe new property is reactive and updates will trigger re-renders.
CVue throws an error because new properties cannot be added to reactive objects.
DThe new property is reactive only if declared with <code>ref()</code>.
Attempts:
2 left
💡 Hint

Think about how Vue tracks reactivity on object properties.

state_output
intermediate
1:30remaining
What is the output when mutating an array inside a reactive object?

Given the following code, what will be logged to the console?

Vue
import { reactive } from 'vue';
const state = reactive({ items: [1, 2, 3] });
state.items.push(4);
console.log(state.items.length);
A3
Bundefined
C4
DThrows a TypeError
Attempts:
2 left
💡 Hint

Arrays inside reactive objects are reactive. What happens when you push an item?

📝 Syntax
advanced
2:30remaining
Which option correctly uses toRefs to avoid losing reactivity when destructuring?

Given a reactive object, which code snippet correctly destructures properties while preserving reactivity?

Vue
import { reactive, toRefs } from 'vue';
const state = reactive({ count: 0, name: 'Vue' });
// Destructure here
Aconst count = toRefs(state.count); const name = toRefs(state.name);
Bconst { count, name } = state;
Cconst count = state.count.value; const name = state.name.value;
Dconst { count, name } = toRefs(state);
Attempts:
2 left
💡 Hint

Think about how to keep reactivity when extracting properties.

🔧 Debug
advanced
3:00remaining
Why does this reactive object not update the template when a nested property changes?

Examine the code below. Why does changing state.user.address.city not update the template?

Vue
import { reactive } from 'vue';
const state = reactive({ user: {} });
state.user.address = { city: 'Paris' };
// Later in code
state.user.address.city = 'London';
ABecause <code>state.user.address.city</code> is a primitive and cannot be reactive.
BBecause <code>address</code> was added after <code>user</code> was made reactive, it is not reactive.
CBecause <code>reactive</code> only tracks top-level properties, not nested ones.
DBecause nested objects cannot be reactive in Vue.
Attempts:
2 left
💡 Hint

Think about when properties are added to reactive objects.

🧠 Conceptual
expert
3:00remaining
What is a key limitation of Vue's reactivity system regarding property deletion?

Which statement best describes Vue's behavior when deleting a property from a reactive object?

AVue does not track property deletions; deleting a property does not trigger reactive updates.
BVue throws an error if you try to delete a property from a reactive object.
CDeleting a property from a reactive object triggers reactivity and updates the UI automatically.
DDeleting a property converts the reactive object into a non-reactive plain object.
Attempts:
2 left
💡 Hint

Consider how Vue tracks changes to object properties.