How it works · JavaScript library for building screens

How React works

You describe what the screen should look like. React works out the smallest set of changes to make it so.

Think of it like this. An editor with two drafts of a page: the one on screen and the one being rewritten. Only the differences get printed.

  1. Your components Functions that return what the screen should show. packages/react
  2. The reconciler Keeps a tree of every component, re-runs the ones that changed, and compares old with new. packages/react-reconciler
  3. The scheduler Decides what to work on next, and stops every few milliseconds so the page stays responsive. packages/scheduler
  4. The DOM renderer Turns the changes into real edits to the page, and listens for clicks and keys. packages/react-dom-bindings

Follow one thing through: You call setCount(1)

  1. The hook writes down an update and its priority. Nothing on screen changes yet.packages/react-reconciler/src/ReactFiberHooks.js
  2. The root is marked as having work, and the scheduler queues it.packages/scheduler/src/forks/Scheduler.js
  3. The work loop walks the tree. For each component that changed, it calls your function again.packages/react-reconciler/src/ReactFiberWorkLoop.js
  4. What your function returned is compared with last time, child by child, and each difference is flagged.packages/react-reconciler/src/ReactChildFiber.js
  5. When the whole tree is done, every flagged change is applied to the page in one go.packages/react-reconciler/src/ReactFiberCommitWork.js
  6. The DOM renderer makes the real edit: here, one piece of text.packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

The clever bit: Rendering can be paused

The work loop does one component at a time and asks shouldYield() between each. If about 5 milliseconds have passed, it stops and lets the browser handle a keypress or paint a frame, then carries on where it left off. That only works because React builds the next screen in a second tree and never touches the page until that tree is finished.

packages/react-reconciler/src/ReactFiberWorkLoop.js

Words you’ll meet

fiber
React’s own record of one component: its state, its children, and what changed.
render phase
Working out what changed. It can be paused or thrown away.
commit phase
Applying the changes to the page. It happens in one go.
hook
A way for a function component to keep something between renders. Hooks are stored in a list, in call order, which is why their order can’t change.

Good questions to ask next

Open React in Bento and ask them there. It reads the project in your browser, draws its parts as a map you can press, and opens the real code behind each one.

Take React apart yourself.

Free and open source. Nothing to install, no account.

More projects, taken apart

Written by hand from the code as it was on 2026-12-04 (commit 1b7f0e2). React belongs to its authors; this page is an independent explanation. Spot a mistake? Tell us.