Add a React root β JSX as truth, live game state, source write-back
site/media/lessons/learn-reactworld.lesson.ts (5 steps) React is a first-class adapter root: an entry with "adapter": "react" mounts as
its own DOM layer in the host stack, z-ordered beside 3D and 2D canvases. A React
root has no scene file β JSX source is the authoritative document, and the
editor works directly against it. In this lesson you add two React roots to a 3D game:
a HUD that displays a live score, and a menu with a clickable button. (Concept
reference: React worlds.)
-
Press Play. The threejs world renders on its canvas; both react worlds mount as transparent DOM layers above it. The HUDβs
Score:counter ticks live β driven byuseGameStatereading theTickercomponent in the 3D world.
React worlds are DOM layers in the same host stack β no canvas, no scene file. -
Read the hierarchy. The native React group contains
HudandMenu, and beneath them the JSX elements as OID-derived nodes βspanandbuttonβ namedComponent:tagfrom instrumentation of the served.tsx.
The hierarchy is derived from the JSX β component:tag nodes, no scene tree. -
Select the HUDβs span. The inspector shows its JSX style props (color, font size, spacingβ¦). There is no scene document behind this panel β you are inspecting the
.tsxsource. -
Edit the color. Change the spanβs color and the edit writes back into
hud.tsxon disk β a real source edit (youβll see it in git), not an overlay or scene change. Reload and press Play again: the rewritten source now drives the HUD to the new color β no in-memory illusion, the.tsxfile is what changed.
Style edits land in the JSX source β reload, and the source drives the new color. -
Click the menu button. React world layers have
pointer-events: noneby default; interactive elements opt back in withpointer-events: auto. The button takes clicks, while clicks on empty layer space fall through to the worlds below.
Recap
New functionality
- Mounted two react worlds (HUD + menu) as DOM layers over a 3D world
- Read live game state in the HUD via useGameState β no polling
- Edited a JSX style in the inspector and saw it write back to hud.tsx
- Clicked a pointer-events: auto button while empty space fell through
New concepts & skills
- adapter: react makes React a root-list peer of threejs/pixijs
- JSX is truth β no scene file; the editor derives hierarchy from OID instrumentation
- the host auto-wraps React roots in GameProvider
- layers default to pointer-events: none; interactive elements opt in
Next lesson β React worlds (manual)
On Your Own!
Extend what you built:
- Add a second stat to the HUD read from another component via useGameState
- Edit the button's className in the inspector and diff hud.tsx/menu.tsx in git
- Give the menu a Resume button that calls game.play.resume() β pair it with the play-control lesson