storybook: React hooks error with material-ui

I have an error with storybook and react hooks

Invariant Violation: 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 invariant (http://localhost:9001/vendors~main.c08119bb1baee695123a.bundle.js:298423:15)
    at Object.throwInvalidHookError (http://localhost:9001/vendors~main.c08119bb1baee695123a.bundle.js:311235:3)
    at Object.useContext (http://localhost:9001/vendors~main.c08119bb1baee695123a.bundle.js:334207:21)
    at useTheme (http://localhost:9001/vendors~main.c08119bb1baee695123a.bundle.js:185294:55)
    at http://localhost:9001/vendors~main.c08119bb1baee695123a.bundle.js:184916:91
    at Object.WithStyles [as render] (http://localhost:9001/vendors~main.c08119bb1baee695123a.bundle.js:185385:21)
    at extract (http://localhost:9001/vendors~main.c08119bb1baee695123a.bundle.js:188834:38)
    at Array.forEach (<anonymous>)
    at extract (http://localhost:9001/vendors~main.c08119bb1baee695123a.bundle.js:188825:25)
    at extract (http://localhost:9001/vendors~main.c08119bb1baee695123a.bundle.js:188830:11)

Example with the same error here https://github.com/alexnofoget/storybook-issue

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 8
  • Comments: 20 (9 by maintainers)

Most upvoted comments

Found a fix, opened a PR

Yowza!! I just released https://github.com/storybooks/storybook/releases/tag/v5.1.0-rc.3 containing PR #6859 that references this issue. Upgrade today to try it out!

Because it’s a pre-release you can find it on the @next NPM tag.

Closing this issue. Please re-open if you think there’s still more to do.

@ndelangen I’m having the same issue. Do you know when this PR will be merged? Is there any work around until then? maybe lowering the react version? I tried, but didn’t work.

I just tried the new code with the 5.1.1 release and I am no longer seeing the error, so this is fixed for us now.

Hi @ndelangen , thanks for looking into this. I have the same issue here. Can we expect the PR to be merged/released soon?

Thanks

I tried it and I still get the same error, my devDeps look like this:

"devDependencies": {
    "@babel/core": "^7.4.5",
    "@storybook/addon-actions": "^5.1.0-rc.3",
    "@storybook/addon-info": "^5.1.0-rc.3",
    "@storybook/addon-links": "^5.1.0-rc.3",
    "@storybook/addons": "^5.1.0-rc.3",
    "@storybook/react": "^5.1.0-rc.3",
    "@types/jest": "24.0.13",
    "@types/storybook__addon-actions": "^3.4.2",
    "@types/storybook__react": "^4.0.1",
    "awesome-typescript-loader": "^5.2.1",
    "react-docgen-typescript-loader": "^3.1.0",
    "babel-loader": "8.0.5",
    "jest": "24.7.1"
  }