Skip to content

FlashcardNot attempted

Why hooks must keep their order

Recall it before you reveal

Why can't hooks be called conditionally?

Space to reveal
Show answer & explanation

React stores hooks on the fiber as a list indexed by call order: slot 0 is the first useState, slot 1 the next hook, and so on. It has no names to go by.

If a hook is skipped on one render, every later hook reads the wrong slot (state from a different hook). Hence the rules: call hooks at the top level, in the same order, only from components and custom hooks.