Answers for "export 'usehistory' (imported as 'usehistory')"

14

usehistory example

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

function Home() {
  const history = useHistory();
  return <button onClick={() => history.push('/profile')}>Profile</button>;
}
Posted by: Guest on May-04-2020
0

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>
  </>)
    
}
Posted by: Guest on November-26-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language