Answers for "rules of react hooks usehistory uselocation"

9

uselocation hook

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, uselocation

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

function HomeButton() {
  let history = useHistory();

  function handleClick() {
    history.push("/home");
  }

  return (
    <button type="button" onClick={handleClick}>
      Go home
    </button>
  );
}
Posted by: Guest on November-28-2019

Code answers related to "Javascript"

Browse Popular Code Answers by Language