Hook Choreography — React

Order React hooks so they don't collide during render: 14 levels of the rules of hooks, call order and reconciliation. 18 levels, right in the browser.

What you learn in this game

React does not know hooks by name. In every render the first hook called gets place 1, the second place 2, and so on, and that place is where React keeps what the hook holds (state, a ref, a memo's result, an effect). As long as the call order is the same in every render, each hook gets its own back.

The rules of hooks: call hooks only at the top level of a component, never inside an if, a loop, or after a return. React remembers what each hook holds by call order. If a render calls a hook the render before did not call (or skips one), the order shifts and React can no longer match what each hook holds.