import { useHistory } from "react-router-dom"; // DEPRECATED
// It is now
import { useNavigate } from "react-router-dom"; // As at March 3, 2022
import { useHistory } from 'react-router-dom';
function Home() {
const history = useHistory();
return <button onClick={() => history.push('/profile')}>Profile</button>;
}
In react-router-dom version 6
useHistory() is replaced by useNavigate() ;
import {useNavigate} from 'react-router-dom';
const navigate = useNavigate();
navigate('/home')
// useHistory() has been changed in v6, so instead use useNavigate()
check out the source link