[Bug] useLocation returns undefined
See original GitHub issueI am attempting to use the useLocation
hook but am getting undefined even when using it from the index.js page provided by a default setup of react-static (v7.1.0)
Environment
System:
OS: macOS High Sierra 10.13.6
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Memory: 449.25 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.15.0 - ~/.nvm/versions/node/v10.15.0/bin/node
npm: 6.9.0 - ~/.nvm/versions/node/v10.15.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Browsers:
Chrome: 76.0.3809.100
Firefox: 68.0
Safari: 11.1.2
npmPackages:
react: ^16.8.2 => 16.8.6
react-dom: ^16.8.2 => 16.8.6
react-static: ^7.0.0 => 7.1.0
react-static-plugin-reach-router: ^7.0.0 => 7.0.10
react-static-plugin-sitemap: ^7.0.0 => 7.0.10
react-static-plugin-source-filesystem: ^7.0.0 => 7.1.0
npmGlobalPackages:
react-static: 7.1.0
of course include any other package versions here if relevant.
Steps to Reproduce the problem
- Installed brand new project with
react-static create
- Modify
src/page/index.js
to this:import React from "react"; import { useLocation } from "react-static"; export default () => { const location = useLocation(); console.log(location); return ( <div style={{ textAlign: "center" }}> <h1>Welcome to React-Static</h1> </div> ); };
- location logs as
undefined
Expected Behavior
I’m assuming it should have some location information, however there aren’t any docs on how to use useLocation
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
useLocation returns undefined - reactjs - Stack Overflow
I use useLocation hook in my app from react-router-dom v5. However, it always returns me undefined. Here is the minimal setup to reproduce ......
Read more >React Router, why useLocation and useHistory might return ...
I was having some head scratching moment when using the useLocation and useHistory hooks with React Router. ... They both returned undefined ....
Read more >UseLocation returns undefined : r/reactjs - Reddit
UseLocation returns undefined. I have my routes in a component named AppEngine like this: <Router> <Navbar /> <Switch> <Route path="/" exact ...
Read more >cannot read properties of undefined (reading 'location ...
Navigate to that route. Observe app crashing with error in useLocation(), where RouterContext is undefined. Expected behavior. I would expect app to not...
Read more >Cannot read properties of undefined (reading 'pathname')
To solve the error, set the to prop on the Link to the specific path, e.g. <Link to="/">Home</Link> . cannot read property pathname...
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
Change that snippet:
I went and looked for
useLocation
because I was getting build errors for usingwindow
inside one of my containers for a dynamic route. Even when adding a check before use window I get this:Here is a snippet of what the
Doc
component was doing: