Why React
You can build websites with plain HTML and JavaScript. People did that for years.
React becomes worth it when the screen has to stay in sync with changing data.
The old way
Suppose a counter button lives in HTML.
You find the button, find the number, add a click listener, and write the new text yourself.
One button is fine. Ten widgets that share count is a tangle of listeners.
The React way
You keep count in state. You describe the label from that state. React patches the DOM.
There is no querySelector. There is no textContent.
The button's children are an expression of count. When count changes, the words change.
Why teams pick React
Components reuse the same UI in many places
State makes interactive screens predictable
A huge ecosystem: routers, forms, testing, UI kits
Used in jobs, including this FoxSchools site
Works on the web, and with React Native on phones
Virtual DOM, in plain words
React keeps a lightweight picture of the tree in memory.
On each render it compares the new picture to the old one.
Then it applies only the real DOM changes it needs, like updating one text node.
You do not have to understand the algorithm to use React. You only need to return the next tree.
Declarative vs imperative
Imperative code says how: find the node, change it.
Declarative code says what: the button should show this count.
React is declarative. That is why bugs like 'forgot to update the badge' happen less often.
Tip: If a screen is a static article, HTML is enough. If it reacts to clicks and data, React shines.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.