title: React navigate router v6 invalid hook call
body: <p>Im trying to redirect my user when the user is logged in. but all my methods i found so far wont work. etg im trying to use useNavigate function using react router v6.</p>
  <p>but for some reason i get the following error:</p>
  <pre><code>Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app
  See react-invalid-hook-call for tips about how to debug and fix this problem.
  </code></pre>
  <p>at:</p>
  <pre><code>/login.jsx:35
  let navigate = useNavigate();
  </code></pre>
  <p>function:</p>
  <pre><code>PerformLogin = () =&gt; {
    let navigate = useNavigate();
    const username = this.state.username;
    const password = this.state.password;
    if (username === '') {
      console.log(&quot;please enter username&quot;);
    } else if (password === '') {
      console.log(&quot;please enter password&quot;);
    } else {
      console.log(&quot;username of login: &quot;,this.state.username);
      axios.post(process.env.REACT_APP_DATAURL + `/login`,{ username: username, password: password },{withCredentials: true})
      .then(res =&gt; {
        res = res.data;
        console.log(res);
        console.log(res.data);
        if (res.type) {
          console.log(&quot;navigating logged in&quot;);
          navigate.push('/crime');
          //return &lt;Navigate to=&quot;/crime&quot; /&gt;;
        }
      })
    }
  }
  </code></pre>
  <p><strong>Q: what do i have to do to fix this and be able to redirect my user?</strong></p>