uses of useNavigate instead of useHistory

remonhasan

Remon Hasan

Posted on June 6, 2022

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

πŸ’– πŸ’ͺ πŸ™… 🚩
remonhasan
Remon Hasan

Posted on June 6, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related