Skip to main content
InterviewHubPRO
Section Overview
Q20

Question 20 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

40%
Vue.js & Composition API (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

What is `v-memo` and how does it optimize virtual DOM sub-tree updates?

senior LevelMost AskedCode ExampleSystem DesignDatabases & SQLData Structures

In Simple Words: Introduced in Vue 3.2, v-memo="[dep1, dep2]" memoizes a chunk of the template:

vue
<div v-for="user in users" :key="user.id" v-memo="[user.id === selectedId]">
  <p>{{ user.name }}</p>
  <p>{{ user.details }}</p>
</div>

If user.id === selectedId has not changed, Vue skips Virtual DOM diffing completely for that entire sub-tree, speeding up large lists by up to 10x!