DEV Community

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

Posted on

3 3

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)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay