React · Senior · Question 42 of 75
"Invalid hook call" error. What's the most likely cause if the component code is correct?
- ✓Correct answer: Two copies of React from different packages ended up in the bundle
- 2The component is declared as an arrow function instead of with
function - 3The component has more than ten hooks, and React doesn't support more
Explanation
Causes: calling a hook outside a component, mismatched react and react-dom versions, or duplicate React. Hooks are tied to the "dispatcher" of a specific React copy. Check with npm ls react; in monorepos and micro-frontends React is made a singleton (peerDependencies, shared in Module Federation).