Render, then commit

React chapter 137 · How React updates the screen · trigger → render → commit · source: react.dev/learn/render-and-commit

The problem

You push a new todo into the array and call setTodos(todos). The array grew, but the screen does not change. React compared the old and new value, saw the same array, and skipped the update.

The pattern that fixes it

Give React a new value: setTodos([...todos, item]). A different reference triggers a render, React diffs the new tree against the old one, and the commit touches only the one <li> that changed.

In plain words

React does not watch your variables. You tell it “here is the new state”, it runs your components again to see what the screen should be, then changes only the parts of the page that differ.

An architect redraws the whole plan on paper (render), but the builder only moves the walls that changed on the drawing (commit).

Terms

trigger
Something asks for an update: setState, new props from a parent, a context or store change.
render
React calls your component functions to get the next UI tree. No DOM is touched yet.
commit
React applies the difference between the old and new tree to the real DOM.

Going deeper

Why mutation is invisible

setState(next) bails out when Object.is(prev, next) is true. push changes the array in place, so prev and next are the very same object. Nothing is scheduled. The same rule powers memo, useMemo deps and selector equality later in the course.

Render is cheap-ish, commit is precise

A render can run many components and still produce zero DOM writes if the output is identical. That is why “avoid re-renders” is a performance tactic, not a correctness rule. Measure renders with the Profiler; measure DOM writes with the Performance panel.

Concurrent rendering

Since React 18 the render phase can be paused, thrown away or restarted (transitions, Suspense). The commit phase never is: it runs synchronously in one go. So render must be pure — no subscriptions, no DOM writes — and side effects belong in effects or event handlers.

Keep learning

Overview

Buy milk Fix login bug Call Grace Review PR #42 Book flights Water plants Write tests Learn render Learn commit Real life: an “Add” button that seems dead until something else re-renders the page. Add todo (push + setTodos(todos)) Re-render for another reason 2items in the array (memory) 2items on screen (DOM) 0DOM writes so far

The click changes memory, not the screen.

Press “Re-render for another reason” and the hidden todos suddenly appear — proof the data was there, React just was never told. Press Re-render for another reason. Now every pushed item shows up at once. Trigger, render, diff, commit, paint ⚡ Trigger [...todos, t]) ƒ Render call TodoList() → new tree li · Learn render li · Learn commit li · Buy milk pure JS · no DOM yet old tree vs new 2 same mono tg ✎ Commit DOM writes: ▣ Paint same array (push) → Object.is → no trigger → nothing below runs Learn render Learn commit Same list. Now each click hands React a brand-new array. What happens after one click Trigger: setTodos([...todos, t]) passes a new array. Object.is(old, new) is false, so React schedules an update. Render: React calls TodoList() again and gets a description of the whole list. Nothing on the page has changed yet. Commit: React touches the DOM exactly once — it inserts that one <li>. The other items are left alone. Paint: the browser draws the new pixels. Then effects run (chapter 139). And the problem version? push keeps the same array, so step 1 never fires and nothing after it happens. Add todo (setTodos([...todos, t])) Re-render with no change 0DOM writes in the last commit 0DOM writes in total

Render many, write few.

“Re-render with no change” bumps the render badge but the DOM-writes counter stays the same: rendering is not updating the page.

More courses

  • Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
  • Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
  • Databases in depth — How a query becomes work. Indexes, isolation, locks, and the plans that explain why a page is slow — not an ORM tour.
  • System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
  • NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
  • Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
  • Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
  • AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
  • Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
  • TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
  • CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
  • Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
  • Docker — What an image is, why layers cache, and how containers find each other on a network.
  • Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
  • Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
  • AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
  • Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.