Question presented to candidate:
"You see shallowRef and shallowReactive in a code review. Explain what they do differently from ref and reactive, and what happens when someone mutates a nested property on them."
What a strong answer should cover:
refandreactiveare deep: nested objects are wrapped in proxies on access, so a write at any depth triggers updates.shallowReftracks only.valueassignment; the value itself is stored as-is (not proxied), so nested mutations are invisible.shallowReactivetracks only its own top-level properties; nested objects stay raw and refs are not unwrapped.- Assigning the same object back to a
shallowRefdoes not trigger, because Vue compares withObject.is. triggerRef()forces ashallowRefupdate after an in-place mutation; it does nothing for ashallowReactive.- Typical uses: large data you replace wholesale, external or immutable state, and holding values that must stay unproxied.
Clarifying questions expected:
- "Is the data replaced as a whole, or edited in place?"
- "Is this about rendering performance, or about keeping an external object unproxied?"
Code / implementation expected: Yes β a short demo showing a nested mutation that does not re-render and a top-level replacement that does.