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

Popular posts from this blog

Remote Method Invokation (RMI) in Java

Changing the Title of Website on Button Click in React Hook tut 14

useContext() in React tut 12