Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

usehistory example

import { useHistory } from 'react-router-dom';

function Home() {
  const history = useHistory();
  return <button onClick={() => history.push('/profile')}>Profile</button>;
}
Comment

useHistory react-router-dom

In react-router-dom version 6 
useHistory() is replaced by useNavigate() ;

import {useNavigate} from 'react-router-dom';
const navigate = useNavigate();
navigate('/home')
Comment

useHistory hook

// useHistory() does not work inside an arrow function 
// notice @ line 9 that the history.push() is inside a usual function. not an arrow function

let myComponent = () => {
    
const history = useHistory();
  function routeChange(){
   history.push("/author");
  }
  
  return(<>
  <button onClick={ routeChange} > redirect </button>
  </>)
    
}

      
      
      
      
Comment

useHistory() hook

// useHistory() has been changed in v6, so instead use useNavigate()

check out the source link
Comment

useHistory

replaced by useNavigate
Comment

usehistory example

import { useHistory } from 'react-router-dom';

function Home() {
  const history = useHistory();
  return <button onClick={() => history.push('/profile')}>Profile</button>;
}
Comment

useHistory react-router-dom

In react-router-dom version 6 
useHistory() is replaced by useNavigate() ;

import {useNavigate} from 'react-router-dom';
const navigate = useNavigate();
navigate('/home')
Comment

useHistory hook

// useHistory() does not work inside an arrow function 
// notice @ line 9 that the history.push() is inside a usual function. not an arrow function

let myComponent = () => {
    
const history = useHistory();
  function routeChange(){
   history.push("/author");
  }
  
  return(<>
  <button onClick={ routeChange} > redirect </button>
  </>)
    
}

      
      
      
      
Comment

useHistory() hook

// useHistory() has been changed in v6, so instead use useNavigate()

check out the source link
Comment

useHistory

replaced by useNavigate
Comment

PREVIOUS NEXT
Code Example
Javascript :: axios request and response intercepters 
Javascript :: detect invalid date js 
Javascript :: how to show calendar in javascript 
Javascript :: @paypal/react-paypal-js 
Javascript :: mongoose in node.js 
Javascript :: how to make a preloader dissapear in html 
Javascript :: display image on button click javascript 
Javascript :: react state value not updating in function 
Javascript :: javascript print array 
Javascript :: how to pass state from one component to another in functional component 
Javascript :: javascript run function based on the page size 
Javascript :: how click button and redirect angular 
Javascript :: razor list to js array 
Javascript :: react scroll direction 
Javascript :: upload files with angular 
Javascript :: what is the function of delete operator in javascript 
Javascript :: new date() javascript 
Javascript :: javascript new line 
Javascript :: How to make remove buttoon on table using js DOM 
Javascript :: remove element onclick javascript 
Javascript :: js object deep clone with lodash 
Javascript :: count using sequelize.fn 
Javascript :: fontsize javascript 
Javascript :: express session mongoose 
Javascript :: creating a module with lazy loading in angular 9 
Javascript :: express octet stream 
Javascript :: check if value is number 
Javascript :: chart js two layer label 
Javascript :: create node js server 
Javascript :: second largest number in array javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =