score:18

Accepted answer

If this issue happens while you're linking the local version of your library in your main project to speed up the development. It might be related to "duplicate version of React".

https://reactjs.org/warnings/invalid-hook-call-warning.html

This problem can also come up when you use npm link or an equivalent. In that case, your bundler might “see” two Reacts — one in application folder and one in your library folder. Assuming myapp and mylib are sibling folders, one possible fix is to run npm link ../myapp/node_modules/react from mylib. This should make the library use the application’s React copy.

In short:

  • run npm link in /your-app/node_modules/react. This should make the React's global link.
  • run npm link react in /your-ui-library. This should make the library use the application’s React copy.

score:1

I have the same issue, working with a rush monorepo, configuring ui-package and building the apps using nextjs.

The solutions was add the follow code on package.json

"resolutions": {
  "react": "17.0.1", // verificate your react version
  "react-dom": "17.0.1"
}

See more here: https://github.com/vercel/next.js/issues/9022#issuecomment-728688452


Related Query

More Query from same tag