the useHistory hook code example
Example: usehistory
import { useHistory } from "react-router-";
function HomeButton() {
let history = useHistory();
function handleClick() {
history.push("/home");
}
return (
<button type="button" onClick={handleClick}>
Go home
</button>
);
}