useState('Ada') passes no identifier, so React can't know which state variable a call refers to by looking at it. It relies on order: React keeps a list of hook slots for each component instance, and during a render it hands out the slots one by one as hooks are called. The first useState gets slot 1, the next hook gets slot 2, every render.
That only works if every render calls the same hooks in the same order. So the Rules of Hooks:
- Call hooks only at the top level of a function component or custom hook: not inside conditions, loops, nested functions,
try/catch/finally, or after an earlyreturn. - Call hooks only from React functions: components and custom hooks (functions named
use…), never from plain functions, class components, event handlers or effects.
If a condition skips a hook, every later hook shifts one slot. With the same number and types of hooks, that is silent: a variable shows another variable's state. With a different count, React throws "Rendered more hooks than during the previous render." or "Rendered fewer hooks than expected. This may be caused by an accidental early return statement." When the hook kinds at a position differ, development builds also log "React has detected a change in the order of Hooks".
The fix is structural: call the hook unconditionally and put the condition inside it (in the effect body, in the value you use), or move the conditional part into a child component that is rendered conditionally, so it gets its own slots.
The react-hooks/rules-of-hooks rule in eslint-plugin-react-hooks catches these at build time. use is the one exception: it can be called in conditions and loops.