storybook-addon-next-router icon indicating copy to clipboard operation
storybook-addon-next-router copied to clipboard

`router is null` - How to lift router provider higher in the component tree?

Open abohannon opened this issue 2 years ago • 9 comments

When running Storybook, I'm getting the error Uncaught TypeError: router is null presumably because I am using useRouter in a provider that's rendering higher in the tree than RouterContext.Provider

My preview.js looks like this

const AppDecorator = (storyFn) => <RootProviders>{storyFn()}</RootProviders>;

export const decorators = [mswDecorator, AppDecorator];

export const parameters = {
  nextRouter: {
    Provider: RouterContext.Provider,
  },
//.....

Is there a way to render the Next router before any other providers? If not, this maybe should be considered a bug because as you'll see from the screenshots below, in a regular build the router is rendered above providers in the tree.

Regular app tree Screen Shot 2022-03-04 at 9 48 20 PM

Storybook tree Screen Shot 2022-03-04 at 8 20 42 PM

abohannon avatar Mar 05 '22 06:03 abohannon