DEV Community

Cover image for uses of useNavigate instead of useHistory
Remon Hasan
Remon Hasan

Posted on

uses of useNavigate instead of useHistory

Github Repository :
Github

The useHistory hook gives you access to the history instance. In General useHistory is used for redirect to particular route after fetch api data or anything else with history. We used it as:

const history = useHistory()
history.push("/path")
Enter fullscreen mode Exit fullscreen mode

sometimes it fails to give you the access to the history instance. As per, useNavigate is the best way to redirect the particular route with your history instance. Here we go:

const history = useNavigate();
history("/path");
Enter fullscreen mode Exit fullscreen mode

Image description

Top comments (0)