<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Simeon Offiong</title>
    <description>The latest articles on DEV Community by Simeon Offiong (@simicodes).</description>
    <link>https://dev.to/simicodes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F921068%2Ff38c4aee-dbbb-4729-b1c3-823bd67c7ba3.png</url>
      <title>DEV Community: Simeon Offiong</title>
      <link>https://dev.to/simicodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/simicodes"/>
    <language>en</language>
    <item>
      <title>The useHistory hook in react router v5 vs the useNavigate hook in react router v6.</title>
      <dc:creator>Simeon Offiong</dc:creator>
      <pubDate>Tue, 06 Sep 2022 15:12:34 +0000</pubDate>
      <link>https://dev.to/simicodes/the-usehistory-hook-in-react-router-v5-vs-the-usenavigate-hook-in-react-router-v6-31km</link>
      <guid>https://dev.to/simicodes/the-usehistory-hook-in-react-router-v5-vs-the-usenavigate-hook-in-react-router-v6-31km</guid>
      <description>&lt;p&gt;React Router DOM is an npm package ( npm - node package manager) that enables you to implement dynamic routing in a web app. It allows you to display pages and allow users to navigate them. It is a fully-featured client and server-side routing library for React.&lt;/p&gt;

&lt;p&gt;In this article I will be concentrating on the UseNavigate in v6 and the useHistory in v5 react router.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic installation:&lt;/strong&gt;&lt;br&gt;
React router dom can be install in react applications using the following package managers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;npm install react-router-dom&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;yarn add react-router-dom&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Reacently, a newer version of react router dom was introduced, that is the &lt;a href="mailto:react-router-dom@v6"&gt;react-router-dom@v6&lt;/a&gt;.&lt;br&gt;
The useNavigate() hook is introduced in the React Router v6 to replace the useHistory() hook. In the earlier version, the useHistory() hook accesses the React Router history object and navigates to the other routers using the push or replace methods. It helps to go to the specific URL, forward or backward pages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useHistory&lt;/strong&gt;&lt;br&gt;
The &lt;em&gt;useHistory&lt;/em&gt; hook gives you access to the history instance that you may use to navigate. &lt;br&gt;
Below is a code snippet to show the useHistory hook.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BCLOFfAG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nr3kzvjsfc3a1i5mh04f.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BCLOFfAG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nr3kzvjsfc3a1i5mh04f.PNG" alt="Image description" width="483" height="290"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useNavigate&lt;/strong&gt;&lt;br&gt;
The &lt;em&gt;useNavigate&lt;/em&gt; hook returns a function that lets you navigate programmatically.&lt;br&gt;
Below is a code snippet to show the useNavigate hook.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tJi50WRl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/haidag7hrr30g3vc9e20.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tJi50WRl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/haidag7hrr30g3vc9e20.PNG" alt="Image description" width="481" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see from the code snippets showing the implementation of the &lt;em&gt;useHistory&lt;/em&gt; hook in react router v5 and the &lt;em&gt;useNavigate&lt;/em&gt; hook in react router v6. &lt;br&gt;
One can easily conclude that the implementation of the &lt;em&gt;useNavigate&lt;/em&gt; which replaces the &lt;em&gt;useHistory&lt;/em&gt; is simple to implement, and in the &lt;strong&gt;useNavigate hook&lt;/strong&gt; the use of the &lt;strong&gt;(.push )&lt;/strong&gt; method is no longer needed.&lt;/p&gt;

&lt;p&gt;I hope you find this helpful.❤️&lt;/p&gt;

&lt;p&gt;Got questions? Send me a message.&lt;/p&gt;

&lt;p&gt;Kindly follow me on the following platforms👏&lt;br&gt;
&lt;a href="https://linkedin.com/in/simicodes"&gt;Linkedin&lt;/a&gt;&lt;br&gt;
&lt;a href="https://twitter.com/simicodes"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://medium.com/@simeonoffiong/"&gt;Medium&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/simicodes/"&gt;DEV&lt;/a&gt;&lt;br&gt;
&lt;a href="https://facebook.com/simicodes"&gt;Facebook&lt;/a&gt;&lt;br&gt;
&lt;a href="https://instagram.com/simicodes"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
