React's Internal Hook Storage Model
What you'll learn: How React keeps track of your hooks behind the scenes using a simple array and call order.
The Hidden Array
When your component renders, React doesn't store hooks by name or some magic key. Instead, it maintains a linear array (like a numbered list) tied to each component instance. Every time you call a hook like useState or useEffect, React:
- Looks at the current position in that array
- Retrieves or initializes the value at that index
- Moves to the next position for the next hook call
Think of it like a vending machine with numbered slots. React remembers "first useState is slot 0, second useState is slot 1, first useEffect is slot 2," and so on. The order of your hook calls determines which slot React reads from.
Why Call Order Matters
This is why conditional hooks break everything:
// ❌ Breaks the array indexing
if (condition) {
useState(0); // Sometimes slot 0, sometimes doesn't exist
}
useState(''); // Sometimes slot 0, sometimes slot 1
React can't use variable names because functions run fresh each render—the only stable thing is the sequence of hook calls. If you skip a hook one render, all subsequent hooks shift positions, and React reads the wrong values from the wrong slots.
The Instance Link
Each component instance (like each <Counter /> in a list) gets its own hook array. That's why two instances of the same component maintain separate state—they're reading from separate arrays in React's memory.
Key Takeaway: React stores hook state in a numbered array per component instance, relying entirely on call order to match hooks to their values—breaking call order breaks everything.