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 example

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

function Home() {
  const history = useHistory();
  return <button onClick={() => history.push('/profile')}>Profile</button>;
}
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 :: Show one popover and hide other popovers 
Javascript :: firebase get current user javascript 
Javascript :: jquery on checkbox checked es6 
Javascript :: js upload json 
Javascript :: generate module with routing in angular 
Javascript :: jquery right click 
Javascript :: typing refs react 
Javascript :: sequelize find one 
Javascript :: if odd js 
Javascript :: electron communicate between main and renderer 
Javascript :: nods js fs append to file 
Javascript :: datatable columns with nullable fields ajax 
Javascript :: delete package-lock.json command 
Javascript :: regex all starting with 
Javascript :: sorting disable in datatable bootstrap 
Javascript :: javascript length of number 
Javascript :: js console log input value 
Javascript :: javascript loop through object array 
Javascript :: select2 preselect option 
Javascript :: javascript replace string 
Javascript :: javascript get uploaded file name 
Javascript :: jquery disable form element 
Javascript :: id of other schema type mongoose 
Javascript :: React Native BUILD FAILED on run-ios 
Javascript :: how to get data from ipfs 
Javascript :: remove array empty values javascript 
Javascript :: limitar la cantidad de decimales en javascript 
Javascript :: ajax data and image upload laravel 
Javascript :: jquery validation plugin 
Javascript :: moment get month name 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =