QuizNot attempted
Conditionally calling a hook
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
- Violates the Rules of Hooks — calling hooks conditionally breaks hook call order, causing React to throw an error or produce inconsistent state
- Hooks are matched to their state by call order
- when
showExtraflips to false, the seconduseStatecall now getsb's slot and React detects the changed hook count (it throws 'Rendered fewer hooks than expected'), so this violates the Rules of Hooks. - Not 'React handles it': React has no names for hooks, only positions.
- Not 'b merges into c' or 'c is frozen': the failure is a hook-order error (or corrupted state slots), not a defined merge.
- Move the condition inside the hook or into a child component.