I'm trying to use the hook useHistory from documentation of react-router-dom.
I keep getting this error: TypeError: Cannot read property 'history' of undefined
Here an example: https://codesandbox.io/s/twilight-meadow-bwnt8?fontsize=14&hidenavigation=1&theme=dark
import React from 'react';
import { useHistory } from "react-router-dom";
function HomeButton() {
let history = useHistory();
function handleClick() {
history.push("/home");
}
return (
<button type="button" onClick={handleClick}>
Go home
</button>
);
}
function App() {
return (
<HomeButton />
);
}
export default App;