Question presented to candidate:
"Our dashboard loads a 20,000-row report into a ref and the page stutters. A colleague suggests shallowRef. When is that the right call, when is it a trap, and where does triggerRef fit in?"
What a strong answer should cover:
- Deep
ref/reactivecreates a Proxy for every nested object you touch and a dependency for every property you read; on large data that cost is real and measurable. shallowReffits data that is replaced as a whole: API responses, immutable snapshots, external store state, big read-only lists.shallowReactivefits flat state objects whose top-level keys change but whose nested values are treated as immutable.triggerRefis for deliberate in-place mutation of ashallowRef(for example many edits batched, then one trigger).- The trap: nested edits silently do not update the UI, and
computedvalues derived from the data go stale until a trigger. - Do not use shallow state for deeply edited data such as forms; measure before optimising.
Clarifying questions expected:
- "Is the data edited in place by the UI, or replaced from the server?"
- "Have we measured where the time goes: reactivity, rendering, or DOM size?"
Code / implementation expected: Yes β load a large list both ways, then show mutate-only vs triggerRef vs an immutable replacement.