An interactive tutorial on how React hooks really work, read from React 19's source: the hook list, the rules of hooks, Object.is and stale closures.
A frontend app built by Ananda Rizki. More of them at Labs.
React Hooks
Tutorial
An interactive tutorial on React hooks as a mechanism rather than an API, for someone who wants to know why the rules exist rather than what they are. It starts before the jargon: a component is a function, a function's variables die when it returns, a closure outlives the call that made it — and React therefore has to keep your state somewhere else and match this render's hook calls to the last render's state with nothing to match on but the order. Ten lessons then trace that machinery one frame at a time, with React 19.1.0's own functions named as they run: mountWorkInProgressHook building the linked list on fiber.memoizedState, updateWorkInProgressHook cloning it cell by cell while currentHook and workInProgressHook walk in lockstep, the dispatcher swapped into ReactSharedInternals.H before your function is called and swapped back the moment it returns. A hook inside an if is not asserted to be dangerous; the same walk runs, the cursor lands on the wrong cell, the variable quietly takes another hook's value, and React's real dev-mode table and its real thrown error are printed verbatim. Three lessons cover state as a value rather than a box — a pushed array that changes the data and nothing else, Object.is deciding a bail-out and disagreeing with === in both directions, and why setCount(c => c + 1) is a different computation rather than a different style. Three more are about closures: a stale one built step by step inside a custom hook, the three fixes and what each one costs, and why a dependency array is one slot rather than a cache. A twelfth view is a recording rather than a drawing — three copies of the same hook running 20 ms intervals on one component, and the arrays they really pushed. A thirteenth runs eleven fixtures through eslint-plugin-react-hooks and shows the one shape it cannot see. Every number on the page was captured from a real render in Chrome, and the last view lists every file, function and script behind it.
Built by Ananda Rizki, a software engineer and designer, one of the small web apps he writes for fun.
Explore more apps on Labs