0
0
Vueframework~5 mins

Shallow ref and shallow reactive in Vue - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a shallowRef in Vue?

shallowRef creates a reactive reference that tracks changes only to the top-level value, not nested properties.

This means if you change a nested object inside it, Vue won't detect that change automatically.

Click to reveal answer
beginner
How does shallowReactive differ from reactive in Vue?

shallowReactive makes only the first level of an object reactive.

Nested objects inside it are not reactive, unlike reactive which makes all nested properties reactive.

Click to reveal answer
intermediate
Why use shallowRef or shallowReactive instead of full reactivity?

They improve performance by avoiding deep tracking of nested properties.

Useful when you don't need to react to changes inside nested objects or when working with large data structures.

Click to reveal answer
intermediate
What happens if you update a nested property inside a shallowReactive object?

Vue will NOT detect the change and will not trigger updates.

You need to replace the whole nested object or use a fully reactive object to track nested changes.

Click to reveal answer
beginner
Show a simple example of creating a shallowRef and updating its nested property.
<pre>import { shallowRef } from 'vue';

const state = shallowRef({ count: 0, nested: { value: 10 } });

// Updating nested property
state.value.nested.value = 20; // Vue will NOT detect this change

// Updating top-level property
state.value = { count: 1, nested: { value: 20 } }; // Vue detects this change</pre>
Click to reveal answer
What does shallowRef track reactively in Vue?
ANo changes at all
BAll nested property changes
COnly the top-level value changes
DOnly array changes
Which Vue function makes only the first level of an object reactive?
AshallowReactive
Bcomputed
Cref
Dreactive
If you update a nested property inside a shallowReactive object, what happens?
AVue detects and updates the UI
BVue ignores the change
CVue throws an error
DVue reloads the page
Why might you choose shallowRef over ref?
ATo track deep nested changes
BTo automatically watch all nested arrays
CTo disable reactivity completely
DTo improve performance by avoiding deep tracking
Which of these is true about shallowReactive?
AIt only tracks changes on the first level
BIt disables all reactivity
CIt makes nested objects reactive
DIt works only with arrays
Explain in your own words what shallowRef and shallowReactive do in Vue and when you might use them.
Think about how deep Vue normally tracks changes and how shallow versions limit that.
You got /5 concepts.
    Describe what happens if you update a nested property inside a shallowReactive object and how you can work around it.
    Consider Vue's reactivity system and how shallow reactivity limits detection.
    You got /4 concepts.