Skip to the chapter
←ReactGGroundwork⚛React
React/Advanced/A17
50 / 57 written chapters
/

The cover
  1. B1Setup & JSX
  2. B2Thinking in React
  3. B3Components
  4. B4Props
  5. B5useState
  6. B6Events & conditionals
  7. B7Lists & keys
  8. B8Forms
  9. B9useEffect
  10. B10Lifting state & styling
  11. B11Guided project
  12. ★Cheat page
  1. I1useRef
  2. I2Context
  3. I3useReducer
  4. I4Custom hooks
  5. I5Effects in depth
  6. I6Routing
  7. I7State architecture
  8. I8Memoisation
  9. I9Boundaries & portals
  10. I10Data fetching
  11. I11Forms at scale
  12. I12State libraries
  13. I13Auth
  14. I14TanStack Query
  15. I15Testing
  16. I16TypeScript
  17. I17Animation
  18. I18E2E testing
  19. I19i18n
  20. I20File uploads
  21. I21Real-time UI
  22. I22shadcn/ui
  23. ★Cheat page
  1. A1Fiber
  2. A2Concurrent
  3. A3Suspense
  4. A4Server Components
  5. A5Server Actions
  6. A6use()
  7. A7Rendering strategies
  8. A8Effect timing
  9. A9External stores
  10. A10Refs in depth
  11. A11Component patterns
  12. A12Performance
  13. A13Accessibility
  14. A14Design systems
  15. A15Advanced TypeScript
  16. A16Architecture at scale
  17. A17Custom renderers
  18. A18Migrating & upgrading
  19. A19Production debugging
  20. A20Review & judgement
  21. A21State machines
  22. A22Feature flags
  23. A23Interview bank
  24. ★Cheat page

⚛A17 · Part 3 · Advanced

Custom renderers

React is not a DOM library. The DOM is one target among several.

3 min read7 sections2 exercises
50 of 57

In this chapter

  • The split nobody notices
  • What already exists
  • A host config, roughly
  • Mutation, persistence and no-op
  • Why this is worth understanding even if you never write one

and 2 more

about 3 min
07On this page
  1. The split nobody notices
  2. What already exists
  3. A host config, roughly
  4. Mutation, persistence and no-op
  5. Why this is worth understanding even if you never write one
  6. The realistic reasons to build one
  7. The idea to take away

The split nobody notices

React is two packages doing two jobs.

PackageDoes
reactComponents, hooks, state, context, the element format. Knows nothing about the DOM.
react-reconcilerDiffing, scheduling, priorities, the fiber tree. Also knows nothing about the DOM.
react-domA host config: how to create a node, set a property, insert a child.

Swap the third and everything else keeps working. That is why useState behaves identically in React Native, and why the reconciler chapter never mentions elements.

What already exists

RendererTargets
React NativeNative iOS and Android views
React Three FiberA three.js scene graph — WebGL
InkA terminal. Used by real CLIs.
React PDFA PDF document
React Test RendererA plain object tree, for assertions

None of these is a fork. They are host configs over the same reconciler, which is the point: the component model turned out to be more general than the DOM.

A host config, roughly

const config = {
  createInstance(type, props) { return new SceneNode(type, props); },
  appendChild(parent, child) { parent.add(child); },
  removeChild(parent, child) { parent.remove(child); },
  commitUpdate(instance, _t, oldProps, newProps) { instance.apply(newProps); },
  prepareUpdate(_i, _t, oldProps, newProps) { return diff(oldProps, newProps); },
  shouldSetTextContent() { return false; },
  getPublicInstance(instance) { return instance; },
  supportsMutation: true,
};

const reconciler = Reconciler(config);
const container = reconciler.createContainer(root, 0, null, false, null, "", console.error, null);
reconciler.updateContainer(<App />, container, null, null);

Thirty-odd methods, and the reconciler supplies everything else — hooks, context, Suspense, transitions, the diff. You describe how to create, insert, update and remove a node in your world; React decides when.

Mutation, persistence and no-op

  • Mutation mode — nodes are modified in place. The DOM works this way.
  • Persistence mode — every change produces a new node tree. Used where the host is immutable, as in some native frameworks.
  • No-op — nothing is committed anywhere. This is how the test renderer works.

Why this is worth understanding even if you never write one

It explains the boundaries

Everything React "cannot do" — measure a DOM node during render, read layout, focus something — is not a limitation of React. It is that those are host concerns, and the reconciler deliberately knows nothing about a host. That is exactly why refs and effects exist: they are the sanctioned doors from React's world into the host's.

It also explains why the reconciler's rules are so strict. Purity, interruptibility, no side effects during render — those hold because the same algorithm has to be correct for a terminal, a 3D scene and a PDF, not just a browser.

The realistic reasons to build one

  • You own a rendering target — a canvas engine, a game UI, embedded hardware — and want the component model over it.
  • A declarative wrapper over an imperative scene graph, which is exactly what React Three Fiber is.
  • Curiosity. Writing one is the fastest way to actually understand the reconciler.

Not to render to the DOM differently. react-dom is one of the most battle-tested pieces of software on the web, and a custom renderer for it would be slower and wrong in ways you would find one at a time.

The idea to take away

React is a scheduling and diffing engine for tree-shaped UIs, with a pluggable back end. Components, hooks and state are the front end and are target-independent. Once that clicks, React Native stops looking like a separate framework, and the strictness of the render phase stops looking arbitrary.

Interview answer, one sentence

"React splits into the component model, a host-agnostic reconciler, and a host config that says how to create and update nodes — which is why the same hooks work in React Native, Ink and React Three Fiber. Knowing that explains why render must be pure and why refs and effects exist: they are the only sanctioned doors to the host."

02Practice this chapter

Opens in the editor: write it, run it, and check it against real tests.

  • 8 testsWrite a host config, for realadvanced
  • 6 testsPick the host config's modeadvanced
All 54 for this level →
A17

Finished reading?

0 of 57 chapters read in this series

→Next stop

  1. A16Previous · A16Architecture at scale
  2. A17you are here
  3. Next · A18Migrating and upgradingNobody rewrites a working application. The skill is moving it while it keeps shipping.5 min read

01On this page

7 sections · 0%

  1. 01The split nobody notices
  2. 02What already exists
  3. 03A host config, roughly
  4. 04Mutation, persistence and no-op
  5. 05Why this is worth understanding even if you never write one
  6. 06The realistic reasons to build one
  7. 07The idea to take away

[] chapters · t top