Ask questionsCannot read property 'location' of undefined at useLocation
<!-- Thank you for contributing!
The issue tracker is meant for bug reports only. This isn't the best place for usage questions. Questions here don't have as much visibility as they do elsewhere. Before you ask a question, here are some resources to get help first:
The best bug report is a failing test in the repository as a pull request. Otherwise, please use the "BUG REPORT" template below.
Remove the template from below and provide thoughtful commentary and code samples on what this feature means for your product. What will it allow you to do that you can't do today? How will it make current work-arounds straightforward? What potential bugs and edge cases does it help to avoid? etc. Please keep it product-centric. -->
<!-- BUG TEMPLATE -->
"react": "^16.11.0", "react-router-dom": "^5.1.2"
https://stackblitz.com/edit/react-router-uselocation-error
1 - Create a variable referencing a useLocation call. 2 - Try to access the variable.
The variable being accessible.
An error happens in line 713 of the react-router.js file of the react-router package.
Uncaught TypeError: Cannot read property 'location' of undefined
at useLocation (react-router.js?4f2e:713)
The fragment is:
...
function useLocation() {
if (process.env.NODE_ENV !== "production") {
!(typeof useContext === "function") ? process.env.NODE_ENV !== "production" ? invariant(false, "You must use React >= 16.8 in order to use useLocation()") : invariant(false) : void 0;
}
return useContext(context).location; // Error here.
}
...
Am I missing something?
Thanks.
Related questions