`router is null` - How to lift router provider higher in the component tree?
See original GitHub issueWhen 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
Storybook tree
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Issues · lifeiscontent/storybook-addon-next-router - GitHub
router is null - How to lift router provider higher in the component tree ? ... ProTip! Updated in the last three days:...
Read more >useNavigate() may be used only in the context of a <Router ...
This error throws in useNavigate. useInRouterContext will check if the component(which uses useNavigate hook) is a descendant of a <Router> ...
Read more >Router - Angular
By default, the router re-uses a component instance when it re-navigates to the same component type without visiting a different component first.
Read more >React Suspense in Practice | CSS-Tricks
This post is about understanding how Suspense works, what it does, and seeing how it can integrate into a real web app. We'll...
Read more >How To Debug React Components Using React Developer ...
The React Developer Tools browser extension gives you an interface for exploring the React component tree of your JavaScript app, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In my case I had to inject the WithNextRouter decorator after my AppDecorator.
So I dropped that from main.js
and brought it into in preview.js
That did the magic on my side
@hisapy
doing like me should help to prevent importing that to ANY story
Hey Aaron @lifeiscontent
maybe you allow ordering / priorisation of presets or put that in documentation?
In any case thanks for your component!