React mental model

Rendering vs committing, reconciliation, keys, StrictMode double-render. Knowing why a key change remounts a subtree solves whole bug classes.

About 30 min read3-question knowledge check

The mental model

React's core promise is one equation: UI = f(state). Your component is a function that takes the current state and returns a description of what the UI should look like — not the UI itself, a description of it. React's job is to make the real DOM match that description, and to do it again whenever the state changes. You never touch the DOM; you change state and re-describe, and React reconciles the difference.

The crucial distinction the whole model rests on: rendering is not the DOM update. "Render" means React calls your function to get the new description (a tree of elements). "Commit" is the separate, later phase where React applies the minimal set of DOM mutations to match it. A component can render many times and commit nothing, because the description came out identical. Confusing these two is the root of most React confusion — "my component re-rendered, that must be slow" is often false, because a render that produces the same output commits nothing to the DOM.

The analogy that sticks: React is an architect who redraws the blueprint (renders) every time requirements change, hands it to a builder (the commit phase) who compares it against the standing building and changes only the walls that actually differ (reconciliation). Redrawing the blueprint is cheap and happens constantly; the builder only touches brick when the drawing genuinely changed. Keys are the labels on the blueprint that tell the builder "this is the same room, just moved" versus "this is a new room, demolish and rebuild" — get them wrong and the builder rebuilds rooms that only moved, throwing away their contents (component state).

What breaks without this model is a whole family of bugs that look unrelated until you see the mechanism. A list that loses its input values when reordered — a key bug. A component that mysteriously keeps stale state across what should be a fresh instance — a key bug in reverse. An effect that runs twice in development and someone "fixes" it by disabling StrictMode — a misunderstanding of what StrictMode is telling you. A form that resets when its parent re-renders — a remount from a changing key or a component defined inside another component. Every one is reconciliation doing exactly what it specifies while you expected object permanence you never actually asked for.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision