[QoL] Warn on missing react-router context
See original GitHub issueWhen testing one of my components that uses the useReactRouter hook, I got the following error:
Cannot destructure property `history` of 'undefined' or 'null'.
19 | active
20 | }) => {
> 21 | const { history } = useReactRouter();
| ^
22 |
23 | const classes = active
24 | ? 'slider__item slider__item--active'
The error itself is a bit ambiguous as it originates from the hook not being able to find the React-Router context. Perhaps a nice addition would be to warn/error on not being able to find the React-Router context.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Cannot unit test components which use <Link /> due ... - GitHub
The problem is that in this case BrowserRouter must be imported from react-router-dom package, which we don't need in a Remix app.
Read more >Authentication with react context and react router v6 problem
I'm trying to build an authentication service using react context with react router v6 routes and I can´t go to the expected route....
Read more >Context - React
Context provides a way to pass data through the component tree without having to pass props down manually at every level. In a...
Read more >Route render prop - React Router v5
The “react-empty” comments are just implementation details of React's null rendering. But for our purposes, it is instructive. A Route is always technically...
Read more >Complete guide to authentication with React Router v6
The <Route /> component can be thought of like an if statement; it will act upon a URL location with its element only...
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 Free
Top 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
I am getting an error:
Using next versions of react-router, react, & react-dom.
here is a codesandbox.
Hmm. In the codesandbox it’s not working (same problem that I originally had), but if I download it and install/run it locally it does. I used
next
in package.json, and pulled use-react-router out of the app when it wasn’t working, so I’m not sure what version it was using. Now, locally it’s4.4.0-beta.6
(check package-lock) and that seems to work ok, so I will give it another try in the original app.