Virtual DOM là representation trong memory của DOM thực.
- Khi state thay đổi, React tạo Virtual DOM mới, so sánh (diff) với Virtual DOM cũ, tính ra minimal set of changes, rồi áp dụng vào DOM thực (reconciliation).
- Giúp tối ưu DOM operations tốn kém, nhưng không phải lúc nào cũng nhanh hơn direct DOM manipulation.
The Virtual DOM is an in-memory representation of the real DOM.
- When state changes, React creates a new Virtual DOM tree, diffs it against the previous one, computes the minimal set of changes, and applies them to the real DOM (reconciliation).
- This optimizes expensive DOM operations, though it is not always faster than direct DOM manipulation for simple cases.