Answers for "history vs useHistory"

1

usehistory

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

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

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

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

difference between useHistory and props.history

//You can use useHistory() in any component, 
//but props.history only in components where the history is available in props

//When you use history.push, you do NOT have to specify the pathname. 

const queryString = new URLSearchParams(params).toString()
    history.push({
      search: "?" + queryString
    });
Posted by: Guest on May-05-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language