Learning on Web Dev Open is free for all.

Framework Internals > Two hundred lines of frameworkNow open React and find your own code
Phase 04Two hundred lines of framework190 of 434

Now open React and find your own code

Every piece of what you just wrote exists in React under a better name and with ten years of edge cases attached.

Concept15 minAI pair

Your element objects are React elements. Your render function is reconciliation. Your hook array is the hooks list on a fiber. Your batching is React’s scheduler. The APIs you would have designed are, broadly, the APIs that exist, which is a reassuring discovery and the main reason for doing this in the wrong order.

Three things yours does not do. It cannot interrupt: your render runs to completion, whereas React can render part of a tree, notice something more urgent, throw the work away and start again, which is what fibers are, a linked list you can pause in the middle of rather than a call stack you cannot. It has no priority: React assigns updates to lanes so that a keystroke beats a background refresh. And it has no Suspense, no error boundaries, no portals and no server rendering.

This is the right moment to say what the rest of the phase does. You now have a mental model that survives contact with the real thing. Everything from here, effects, state placement, rendering modes, hydration, caching, is decisions layered on top of the machine you just built, and you can always drop back down to "what does this do to the tree" when an explanation gets hand-wavy.

You should now be able to

  • Map each part of your framework onto its React equivalent
  • Name three things React does that your version does not
Ask the community

Loading…