Invalid hook call on login page
See original GitHub issueDescribe the bug I’m getting the following error:
(node:18527) UnhandledPromiseRejectionWarning: Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
at resolveDispatcher (/Users/david/workspace/dongwon-api/node_modules/react/cjs/react.development.js:1465:13)
at Object.useState (/Users/david/workspace/dongwon-api/node_modules/react/cjs/react.development.js:1496:20)
at ae (/Users/david/workspace/dongwon-api/node_modules/styled-components/dist/styled-components.cjs.js:1:13232)
at processChild (/Users/david/workspace/dongwon-api/node_modules/admin-bro/node_modules/react-dom/cjs/react-dom-server.node.development.js:3043:14)
at resolve (/Users/david/workspace/dongwon-api/node_modules/admin-bro/node_modules/react-dom/cjs/react-dom-server.node.development.js:2960:5)
at ReactDOMServerRenderer.render (/Users/david/workspace/dongwon-api/node_modules/admin-bro/node_modules/react-dom/cjs/react-dom-server.node.development.js:3435:22)
at ReactDOMServerRenderer.read (/Users/david/workspace/dongwon-api/node_modules/admin-bro/node_modules/react-dom/cjs/react-dom-server.node.development.js:3373:29)
at renderToString (/Users/david/workspace/dongwon-api/node_modules/admin-bro/node_modules/react-dom/cjs/react-dom-server.node.development.js:3988:27)
at html (/Users/david/workspace/dongwon-api/node_modules/admin-bro/lib/frontend/login-template.js:73:53)
at processTicksAndRejections (internal/process/task_queues.js:94:5)
at async /Users/david/workspace/dongwon-api/node_modules/@admin-bro/express/lib/authentication/login.handler.js:19:23
Installed libraries and their versions
- admin-bro@3.4.0
- @admin-bro/express@3.1.0
- @admin-bro/sequelize@1.2.1
- react@16.13.1
- react-dom@16.13.1
To Reproduce Steps to reproduce the behavior:
- Use
buildAuthenticatedRouter
to create AdminBro router. - Run the app & visit
/admin
Additional context There’s a closed issue about this matter, but I was not able to resolve this problem after removing node_modules or by adding react & react-dom as dependencies.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:25 (3 by maintainers)
Top Results From Across the Web
Invalid Hook Call Warning
There are three common reasons you might be seeing it: You might have mismatching versions of React and React DOM. You might be...
Read more >Invalid hook call. Hooks can only be called inside of the ...
I had this issue when I used npm link to install my local library, which I've built using cra . I found the...
Read more >Invalid hook call on login page · Issue #810
Describe the bug I'm getting the following error: (node:18527) UnhandledPromiseRejectionWarning: Error: Invalid hook call.
Read more >Form giving error : 'Error: Invalid hook call. Hook
Topic: Form giving error : 'Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This...
Read more >Login redirect but has Invalid Hook Call-Reactjs
Coding example for the question Reactjs - Login redirect but has Invalid Hook Call-Reactjs.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed by using same react/react-dom versions as in admin-bro dependencies: “react”: “=16.13.1”, “react-dom”: “=16.13.1”
Ok so i just wrote
"styled-components": "=4.4.1"
in my package.json and it started working 😂. From the third line of stacktraceat ae (C:\Users\maxim\WebstormProjects\portfolio\node_modules\styled-components\src\utils\isStaticRules.js:6:54)
i saw that it also uses my newest styled-components package, then it goes to my latest React package. I use Yarn. I assume that it saw that mystyled-components
version and the one in adminjs are compatible (though not the same, i checked) so it linked it to share with adminjs. That somehow caused the usage of another React version i described above. Thats how i understand it, though it’s kinda a bit crazy. I would be glad if someone can clear this up more.