React tạo Virtual DOM (JS object) đại diện UI. Khi state thay đổi, tạo VDOM mới, so sánh (diffing) với VDOM cũ, chỉ cập nhật DOM thật phần khác biệt.
Diffing O(n) nhờ: so sánh cùng level, key prop cho lists, khác type = rebuild.
React maintains a Virtual DOM (a JavaScript object tree) representing the UI.
- When state changes, React creates a new VDOM, diffs it against the previous one, and applies only the changed parts to the real DOM.
- Diffing is O(n) thanks to: comparing only the same tree level, using the
keyprop for lists, and completely rebuilding subtrees when element types change.