question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Storybook preview hooks can only be called inside decorators and story functions.

See original GitHub issue

In NextJS 11.0.1 the initial Storybook does not render and throws an error:

Storybook preview hooks can only be called inside decorators and story functions.
Error: Storybook preview hooks can only be called inside decorators and story functions.
    at invalidHooksError (hooks.js:240)
    at useStoryContext (hooks.js:442)
    at Module.useGlobals (hooks.js:487)
    at WithNextRouter (decorators.js:11)
    at hooks.js:186
    at decorators.js:26
    at decorators.js:62
    at renderWithHooks (react-dom.development.js:14985)
    at mountIndeterminateComponent (react-dom.development.js:17811)
    at beginWork (react-dom.development.js:19049)

I use preview.tsx and my app initially does not render with the above error. But client side navigation works and renders accordingly.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dfallingcommented, Aug 23, 2021

I’m fully updated with NextJS, Storybook, and storybook-addon-next-router and experiencing the same issue. My project’s pretty complex so I’ll try to make a simpler project that reproduces the issue.

0reactions
lifeiscontentcommented, Jan 28, 2022

@Myzel394 the issue of the reproduction @dfalling had was due to having @react-theming/storybook-addon which is using the wrong hooks that storybook provides for addon creators. You might also be using an addon which also does this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Storybook preview hooks can only be called inside ... - GitHub
Got the Storybook preview hooks can only be called inside decorators and story functions. error. Our decorator looks something like: import ...
Read more >
React js using useState Hook - Stack Overflow
Storybook preview hooks can only be called inside decorators and story functions. Please help. My Full component import React,{ useCallback } ...
Read more >
Decorators - Storybook - JS.ORG
A decorator is a way to wrap a story in extra “rendering” functionality. Many addons define decorators to augment your stories with extra...
Read more >
Don't export hooks with the same names as the core React ...
I often end up importing the wrong one, resulting in a Storybook preview hooks can only be called inside decorators and story functions...
Read more >
How to build connected components in Storybook - Medium
A decorator is wrapper code that runs inside the preview iframe. They enable you to control the story layout, how it's rendered, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found