useHistory in React Router Tut 19

useHistory in React Router


import React from 'react';
import {useHistoryfrom 'react-router-dom';
let User = () =>{
  
    var history = useHistory();
    return(
        <>
   <h1> user page </h1>
   <button onClick={()=>history.goBack()}>GO Back</button> <br/><br/><hr/>
   <button onClick={()=>history.push('/')}>Hompage</button>
        </>
    )
}

export default User;

useHistory gives the information about pages with visited , so that we can go back to previous 
page using goBack()  function and can visit to any page we want using push('page url')
and many more functionality is available in useHistory like goForward() etc.

































Comments