A virtual DOM is a framework’s in-memory tree representing what a page’s DOM should look like. React uses this representation to update the page without requiring developers to manipulate DOM nodes directly. section 1.2.1 section 4.4
When component output changes, React compares the current virtual DOM with its previous version, then reconciles the difference by changing the page’s DOM. This lets application code focus on state and rendered output rather than DOM operations. section 4.4
import React, {useState} from "react";
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<div>The count is {count}.</div>
<button
onClick={() => {
setCount(count + 1);
}}
>
Increment count
</button>
</div>
);
}
A stateful counter shows a user interaction changing component state and the rendered count. section 1.2.1
This abstraction has a startup tradeoff: JavaScript-defined pages must run code before appearing, and framework code adds work. Server-side rendering can provide the page before JavaScript runs. section 4.4



