HomeToolsAbout a20k

History

useHistory

The useHistory hook gives you access to the history instance that you may use to navigate

import { useHistory } from "react-router-dom"; function HomeButton() { const history = useHistory(); function handleClick() { history.push("/home"); } return ( <button type="button" onClick={handleClick}> Go home </button> ); }

Typing Router history object

import { RouteComponentProps } from 'react-router-dom'; type RouteHistory = RouteComponentProps['history']; const history: RouteHistory = useHistory();
© VincentVanKoh