"매 DOM mutation 의 expensive — 매 abstraction 의 batch". React 의 Virtual DOM (2013). 매 modern: 매 fine-grained reactivity (Solid, Svelte, Vue 3) 의 vDOM 의 supersede 의 trend. 매 pure DOM (vanilla, htmx) 의 revival.
매 핵심
Real DOM
매 browser 의 tree.
매 mutation 의 reflow / repaint 의 trigger.
매 manual update 의 error-prone.
Virtual DOM (React)
매 lightweight JS object 의 in-memory.
매 declarative state.
매 diff + 매 reconciliation 의 minimal real DOM update.
매 React 의 algorithm
매 새 Virtual DOM tree.
매 diff vs 매 previous (heuristic O(n)).
매 minimal real DOM mutation.
매 React 의 heuristic
Different type → 매 entirely new tree.
key attribute → 매 stable child identity.
Component type same + props different → 매 update only changed.
functionCounter(){const[count,setCount]=useState(0);return(<buttononClick={()=>setCount(count+1)}>Count:{count}</button>);}// React 가 매 setCount 시 의 새 vDOM → diff → 매 button text 만 update.
key for stable identity
functionList({items}){return(<ul>{items.map(item=>(<likey={item.id}>{item.name}</li>// 매 key 의 stable identity
))}</ul>);}
useMemo / React.memo
constExpensiveItem=React.memo(({item,onClick})=>(<divonClick={onClick}>{item.name}</div>));functionList({items,onSelect}){// 매 stable callback for memoization
consthandleSelect=useCallback((id)=>onSelect(id),[onSelect]);constsorted=useMemo(()=>items.sort((a,b)=>a.priority-b.priority),[items]);returnsorted.map(item=><ExpensiveItemkey={item.id}item={item}onClick={handleSelect}/>);}
Solid (signals, no vDOM)
import{createSignal}from'solid-js';functionCounter(){const[count,setCount]=createSignal(0);return(<buttononClick={()=>setCount(count()+1)}>Count:{count()}</button>);}// 매 specific text node 의 update — 매 component re-render X.
Svelte (compile-time)
<script>letcount=0;</script><buttonon:click={()=>count++}>
Count: {count}</button><!-- 매 compile 의 imperative code 의 generate -->
<buttonhx-post="/click"hx-target="#count"hx-swap="innerHTML">
Click me
</button><spanid="count">0</span><!-- 매 server 가 매 HTML 의 return → 매 swap -->
Direct DOM (vanilla)
constbutton=document.querySelector('button');letcount=0;button.addEventListener('click',()=>{count++;button.textContent=`Count: ${count}`;// 매 direct mutation
});