I want to go to another page when I click on the button and I try this code but I got this error “TypeError:Cannot read properties of undefined (reading ‘ push’)”
How I can solve it problem? Can anyone help me?
import { useHistory } from 'react-router-dom';
function app() {
let history = useHistory();
const redirect = () => {
history.push('/pathOfMyPage ');
}
return (
<div>
<button onClick={redirect}>Click Here </button>
</div>
);
}