"react": "^16.8.6",
"react-router": "^6.0.0-alpha.2",
"react-router-dom": "^6.0.0-alpha.2"
Try to use history hook in a React function component:
import { useHistory } from 'react-router-dom';
...
const history = useHistory();
History should work as expected.
Getting the error:
export 'useHistory' was not found in '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 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 pushTypeError: 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
Most helpful comment
Same here.