React-router: export 'useHistory' was not found in 'react-router-dom'

Created on 9 Mar 2020  路  8Comments  路  Source: ReactTraining/react-router

Version

"react": "^16.8.6",
"react-router": "^6.0.0-alpha.2",
"react-router-dom": "^6.0.0-alpha.2"

Steps to reproduce

Try to use history hook in a React function component:
import { useHistory } from 'react-router-dom';
...
const history = useHistory();

Expected Behavior

History should work as expected.

Actual Behavior

Getting the error:
export 'useHistory' was not found in 'react-router-dom'

Most helpful comment

I'm using react-router-dom 5.2.0 and got this error as well..
And when it imports i cant use its properties, like push

TypeError: Cannot read property 'push' of undefined

Same here.

All 8 comments

There is no useHistory hook in 6.0. Switch back to 5.1.2 or adjust your code to not use that hook.

@timdorr I updated react-router-dom to 5.1.2 still i am getting error .../@types/react-router-dom has no exported member 'useHistory'

I'm using react-router-dom 5.2.0 and got this error as well..
And when it imports i cant use its properties, like push

TypeError: Cannot read property 'push' of undefined

I'm using react-router-dom 5.2.0 and got this error as well..
And when it imports i cant use its properties, like push

TypeError: Cannot read property 'push' of undefined

Same here.

same issue here.

Using Typescript, I fixed this error by updating the types definition to v5.....
npm install -save-dev @types/react-router-dom

There is no useHistory hook in 6.0. Switch back to 5.1.2 or adjust your code to not use that hook @timdorr , if useHistory can't be found in react-router-dom, where can we find it? or should i use History package

same issue as @sylwiasuwalska using 5.2.0.

In my teams react component library (supports CJS and ESM module formats) I have a component using useHistory and when I import it within a component whose ancestor (parent up the tree) is a BrowserRouter, I get TypeError: Cannot read property 'push' of undefined

Related issue: https://github.com/ReactTraining/react-router/issues/6939

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davetgreen picture davetgreen  路  3Comments

andrewpillar picture andrewpillar  路  3Comments

maier-stefan picture maier-stefan  路  3Comments

ackvf picture ackvf  路  3Comments

imWildCat picture imWildCat  路  3Comments