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

PREVIOUS NEXT
Code Example
Javascript :: js get array item by property 
Javascript :: create react app and tailwind 
Javascript :: javascript emit sound 
Javascript :: express send raw html 
Javascript :: javascript clear sembols 
Javascript :: login discord token 
Javascript :: get age by birthday js 
Javascript :: javascript check empty object 
Javascript :: regex find img tag 
Javascript :: discord js delete message after time 
Javascript :: once content is loaded run function 
Javascript :: default ordering of datatable to be removed 
Javascript :: javascript numero al cuadrado 
Javascript :: regex cpf javascript 
Javascript :: fibonacci js code 
Javascript :: parsley cdn 
Javascript :: foreach element in class javascript 
Javascript :: react-native-cli remove 
Javascript :: htaccess for react 
Javascript :: javascript replace <br with n 
Javascript :: javascript change url without reload 
Javascript :: binary to ascii javascript 
Javascript :: refresh page after success ajax 
Javascript :: statements and expressions in js 
Javascript :: ejs partial pass value 
Javascript :: regular expression replace a dot 
Javascript :: jquery on 2 events 
Javascript :: UnhandledPromiseRejectionWarning: MongoNotConnectedError: 
Javascript :: jquery how to fnd id 
Javascript :: iso string to timestamp javascript 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =