Section 1 · Why React exists

The problem React was invented to fix

You already felt it in the JavaScript module. Let's name it — then see how React makes it disappear.

🎯 In one line: in plain JS you tell the page how to change, step by step; in React you describe what the UI should look like for the current data, and React does the changing.

1The pain: manual re-rendering

Remember the vanilla Notes app? Every time the data changed, you had to rebuild the HTML and redraw the list:

// the vanilla JS way — you manage the DOM by hand
function render() {
  list.innerHTML = "";                    // wipe
  notes.forEach(n => {                     // rebuild
    const li = document.createElement("li");
    li.textContent = n.text;
    list.appendChild(li);
  });
}
addBtn.addEventListener("click", () => {
  notes.push(newNote);
  render();   // ← you must remember to call this EVERY time
});
The trap Forget one render() and the screen silently shows stale data. In a big app with dozens of things changing, hand-syncing the DOM becomes a nightmare of bugs.

2The React idea: describe, don't redraw

React flips it around. You write a function that says "for this data, the UI looks like this". When the data changes, React re-runs your function and updates only what actually changed — automatically.

😩 Vanilla JS — imperative

"Find the list. Clear it. Loop the notes. Make an li for each. Append them. …and remember to redo all that on every change."

😌 React — declarative

"The list is the notes mapped to items." You state the relationship once; React keeps the screen matching the data.

3The same list, the React way

// React: describe what the UI IS for the given notes
function NoteList({ notes }) {
  return (
    <ul>
      {notes.map(n => <li key={n.id}>{n.text}</li>)}
    </ul>
  );
}
// change notes → React re-renders. No manual DOM code, ever.
What is that HTML doing inside JavaScript? That's JSX — HTML-like syntax you write directly in JS. It's the single most distinctive thing about React, and you'll get comfortable with it fast. A build tool turns JSX into normal JS before it runs.
🧠

Quick check

1. In plain JavaScript, what did you have to do after every data change?
You called render() by hand every time — easy to forget, and the source of many bugs.
2. React is "declarative" — meaning you…
Declarative = state the result; React figures out the DOM changes to get there.
3. The HTML-like syntax written inside React JavaScript is called…
JSX lets you write markup directly in JS; a build step compiles it to plain JavaScript.
🔓 You're reading a free chapter of React — the first two are open.
Unlock the rest of this course with a one-time payment.
Unlock this course →
🔓 See course prices