Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

equivalent of useHistory in react

import { useHistory } from "react-router-dom"; // DEPRECATED
// It is now
import { useNavigate } from "react-router-dom"; // As at March 3, 2022
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 :: flutter circularprogressindicator 
Javascript :: document jquery 
Javascript :: remove animation css javascript 
Javascript :: javascript character count 
Javascript :: Jspinner max and min value 
Javascript :: jQuert latest cdn 
Javascript :: ajax get with parameters 
Javascript :: adding event listener keypress event in javascript 
Javascript :: javascript maximum date 
Javascript :: prodigy math game add item by id 
Javascript :: remove trailing slash javascript 
Javascript :: encodeurl in javascript 
Javascript :: open a html file using js 
Javascript :: get only one value from object array javascript 
Javascript :: jquery validation form submit 
Javascript :: how do i remove all vowels from a string in javascript and return the result 
Javascript :: how to change background image for a webpage 
Javascript :: javascript set timeout 
Javascript :: s3.getobject nodejs example async await 
Javascript :: jquery set a value in td 
Javascript :: div click outside to hide javascript 
Javascript :: bootstrap cdn for react 
Javascript :: typescript css variables 
Javascript :: electronjs npm start in full screen 
Javascript :: GET req with js 
Javascript :: trigger send parameter 
Javascript :: react date picker disable past dates 
Javascript :: js dynamic import js 
Javascript :: javascript get distinct values from array 
Javascript :: jquery replace text in button 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =