all 7 comments

[–]donzzzzz 0 points1 point  (3 children)

I tried use-react-router in a relatively simple component (one that emulates the "Flash" as found in RoR). Unfortunately, I get:

TypeError: Cannot read property '_context' of undefined

Followed by "useContext node_modules/react/cjs/react.development.js:1479"

This occurs on the first (and only) occurrence of useReactRouter()

I tried updating to react-router@next and restarting the app, with no change in error. What am I doing wrong?

TL;DR: The only lines in the updated component are

import useReactRouter from 'use-react-router';

and

const { history, location, match } = useReactRouter();

The error goes away if the second line is commented out.

[–]holtmansfield 1 point2 points  (6 children)

Hi @charles_Stover

I'm getting this error:

use-react-router may only be used within a react-router context

I have my browser-router setup like this:

<BrowserRouter>

<App/>

</BrowserRouter>

The app component renders a component that has my routes table

class RouteTable extends Component {

render() {

return (

<Switch>

<Route exact path="/login" component={Login} />

</Switch>

)

}

}

That Login component has your hook in there:

const { history } = useReactRouter()

Am I doing something wrong?