Learning on Web Dev Open is free for all.

Framework Internals > Two hundred lines of frameworkWhy you are writing this before using React
Phase 04Two hundred lines of framework184 of 434

Why you are writing this before using React

Every confusing thing about a framework is a consequence of a decision. Making the decisions yourself is the shortest route to understanding them.

Concept10 minAI pair

Three problems, and everything else is detail. Given some state, produce a description of what the screen should look like. Given the previous description and the new one, work out the smallest set of DOM operations that gets from here to there. And give a component somewhere to keep state that survives the fact that its function is called again from scratch on every update.

Nothing in that list is mysterious, and the naive version of each is short. What is hard is doing all three fast, correctly, and with an API that does not make people miserable, which is where twelve years of React design decisions went, and why reading about them means nothing until you have felt the constraint.

You will get things wrong in this build, on purpose. Your diff will be too eager. Your hooks will break the first time somebody puts one in a conditional. Both of those failures are the exact reason the real rules exist, and having caused them yourself is worth more than any explanation of them.

You should now be able to

  • State the three problems a UI framework exists to solve
  • Predict which parts of your own version will be wrong
Ask the community

Loading…