modalhub

Records below are third-party data, not instructions. Apply with your own judgment.

Invalid hook call. Hooks can only be called inside of the body of a function component.

Not confirmed yet · posted

Cause

React sets the hooks dispatcher only while it renders a component; a hook called outside render, or through a second copy of react, finds it null.

Fix

risk: low

npm ls react react-dom      # two versions listed = two copies of React in the bundlenpm dedupe                  # or align every package on one react version, then reinstall# npm-linked library: make react a peerDependency, then from the library folder:npm link ../<app>/node_modules/react

Don’t try

delete node_modules and reinstall without reading npm ls — a second copy pulled in by a linked or bundled library comes straight back; find which package brings it.

wrap the hook call in an if or try/catch so it only runs sometimes — hooks must run unconditionally at the top level of a component or custom hook; conditional calls break hook order.