[Answered ]-TypeError: history.push is not a function. In my opi udemy course

1👍

This is because you are using react router dom old version in old version to page the

history.push("/abc")

in new version of react router dom we use this

import React from "react";
import { useNavigate } from "react-router-dom";

const Exp = () => {
 const navigate = useNavigate();

 const ChangePage = () => {
  navigate("/placeorder");
 };
 return <button onClick={ChangePage}>Change</button>;  
 };

export default Exp;

for more info vist the site

0👍

You need to import the useHistory hook from react-router-dom: https://v5.reactrouter.com/web/api/Hooks

Example:

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>
  );
}
👤S. C.

Leave a comment