Invalid hook call on React component

Trying out my first React Bit component today.

My component uses React Hooks. It works locally during dev, but after publishing it errors:

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.

Published at https://bit.dev/devth/github/git-hub-org-cards

Is the bit react compiler using a different version? Anyone else seen this problem? Having duplicate Reacts is listed as one of the reasons this error would be thrown.

Update: I ran console.log('react version', React.version) in the playground and noticed it’s running 16.8.6 while my component depends on 16.10.2. Can I specify the version used in the playground?

Thanks!

1 Like

+1 Having the same issue

this is likely due to two copies of react being loaded.

I managed to solve this with an override in the bit config (either package.json “bit” or in bit.json):

...
"overrides": {
    "*": {
      "dependencies": {
        "react": "-"
      },
      "peerDependencies": {
        "react": "+"
      }
    }
}
...

Thanks! Moving react to peerDependencies worked for me!