The Call Order Invariant
What you'll learn: Why React requires hooks to be called in the exact same order on every render of a component.
The Fundamental Contract
React maintains an index-based registry of hooks for each component instance. On the first render, React stores your hook calls in order: slot 0, slot 1, slot 2, etc. On every subsequent re-render, React expects to find exactly the same hooks in exactly the same slots.
This requirement is called the Call Order Invariant: the sequence of hook calls must never change between renders.
Why Order Matters
Remember that React doesn't identify hooks by name or type—it relies entirely on position. If your first hook call is useState, React stores that state value in slot 0. If your second hook call is useEffect, React stores that effect in slot 1. On re-render, React assumes slot 0 is still a useState and slot 1 is still a useEffect.
If you conditionally skip a hook, React's internal pointer gets out of sync. What React thinks is slot 2 might actually be your slot 3 hook. This causes data corruption: you might read the wrong state value or run the wrong effect.
The Analogy
Think of React's hook storage like a coat check with numbered tickets. You hand in three coats and get tickets 1, 2, 3. When you return, you must claim them in the same order. If you skip ticket 2, you'll get the wrong coat for ticket 3—React has no way to know you changed the sequence.
This is why conditional hooks break everything: they violate the order React depends on to match stored values with hook calls.
Key Takeaway: React's hook system depends on a strict call order invariant—every hook must be called in the same sequence on every render, because React uses position, not identity, to track hook data.