React · Senior · Question 42 of 75

"Invalid hook call" error. What's the most likely cause if the component code is correct?

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).

Further reading

Problem with a question

React · Senior · question 42

Test yourself

Take the React · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz