title: In Reactjs why 'history' of undefined error
body: <p>I have this functional component. </p>
  
  <pre><code>import { useHistory } from "react-router-dom";
  
  function ProfileForm(props) {
  const form = useForm();
  const {
  register,
  handleSubmit,
  errors
    } = form;
  const history = useHistory(); // TypeError: Cannot read property 'history' of undefined 
  ......
      }
  </code></pre>
  
  <p>Why this error? Btw, I installed react-router-dom. How to use history in the functional components? </p>
  
  <p>Update more code:-</p>
  
  <pre><code> axios.post('http://localhost:8080/profile', profile)
    .then(res =&gt; {
      history.push({
        pathname: "/OnSubmit",
        state: {
          response: res.data,
          msgVariant: "success"
        }
      })
    }).catch((error) =&gt; {
      // handle this error
      history.push({
        pathname: "/OnSubmit",
        state: {
          response: error.message,
          msgVariant: "danger"
        }
      })
    })
  </code></pre>
  
  <p>Later I am using history as above? </p>