React
UI = a function of state. That is the whole framework.
▶ the lesson · narrated sketch video · tap for sound
the intro
React is a JavaScript library for building user interfaces out of small, reusable pieces called components. You describe what the screen should look like for a given state, and React figures out how to update the page when that state changes. Once it clicks, you stop fighting the DOM forever.
the sample
a real component, in full
function Counter() {
const [n, setN] = useState(0)
return (
<button onClick={() => setN(n + 1)}>
Clicked {n} times
</button>
)
}fun fact ✦
React was born at Facebook in 2011 to tame their own ad-code chaos. Now it runs a huge chunk of the internet.
the docs
the deep dive
the ideas behind the video — concepts, diagrams, a walkthrough and the traps to avoid
Before React, you wrote the screen twice: once at load, then again as step-by-step DOM surgery on every change. React deletes the second half. You describe what the screen looks like for the current state — a plain function — and the library computes the minimum updates. State changes, screen follows.
describe the screen, not the surgery
key terms
component
A function that takes props and returns UI. Compose them like functions; reuse them like building blocks.
function Card() { ... }props
Inputs passed from parent to child, read-only inside. Like function arguments for markup.
<Card title="Hi" />state
Data a component owns that changes over time. Every update schedules a re-render.
useState(0)hook
A use-prefixed function that taps into React powers: state, effects, context. Rule: call hooks at the top level only.
useState, useEffecthow it works
- 1Break the UI into components
One piece per job: Card, Badge, SearchBar. If you can name it, it can be a component.
- 2Find the minimal state
What actually changes over time? Compute everything else during render instead of storing it.
- 3Wire events to setState
Handlers call the setter; React re-renders, diffs the trees, and patches only what changed.
- 4Lift shared state
Two siblings need the same data? Move it to their closest common parent and pass it down as props.
the code, explained
a complete component — the whole idea in eight lines
side by side
props
- passed in by the parent
- read-only inside the child
- like function arguments
- changes come from above
state
- owned by the component
- private and updatable
- changes via the setter
- updates trigger re-render
Using the array index as key works until the list reorders or an item is deleted — then React misidentifies elements and scrambles their internal state: focus jumps, inputs keep old text. Keys are identity, not decoration. Use the stable id from your data.
quick answers
Why not just vanilla JavaScript?
For mostly-static pages, skip React. The moment the UI has lots of changing state, manual DOM syncing becomes your app — React automates exactly that.
What is the virtual DOM, really?
A cheap JavaScript description of your UI. React diffs the new one against the old and touches the real DOM as little as possible.
Do I still need useMemo everywhere?
Less every year — the React Compiler now memoizes automatically. Measure first; sprinkle optimization second.
quick hits about React
short answers · interviews, tips, trivia & hidden gems
Props or state?watch ↗
Why does your useEffect loop forever?watch ↗
What does the virtual DOM do?watch ↗
Two components need the same data?watch ↗
Forms the React way?watch ↗
Reuse logic between components?watch ↗
Why not use the index as key?watch ↗
One component crashes everything?watch ↗
Still writing useMemo everywhere?watch ↗
Forms in React 19?watch ↗
React had another name?watch ↗