title: history.push is not working after login function
body: <p>I am trying to use <code>history.push()</code> after setting the token. Somehow the page doesn't redirect to a new path. I have used <code>useHistory</code> feature for accessing history. Once I reload the page it is redirecting to home. I tried other sort of hacks but unable to find solution. Please help.</p>
  <p><strong>App.js</strong></p>
  <pre><code>function App() {
    const [isAuthenticated, setAuthenticated] = useState(false);
    useEffect(()=&gt;{
      if(cookie.get('authorization')){
        setAuthenticated(true);
      }
      else{
        setAuthenticated(false);
      }
    },[])
    return (
      &lt;Router&gt;
        &lt;Switch&gt;
          &lt;Route exact path=&quot;/&quot;&gt;
            {isAuthenticated?&lt;Redirect to=&quot;/home&quot;/&gt;:&lt;Login /&gt;}
          &lt;/Route&gt;
          &lt;PrivateRoute exact path=&quot;/user/:id&quot; component={UserDetail} auth={isAuthenticated} /&gt;
          &lt;PrivateRoute exact path=&quot;/createuser&quot; component={CreateUser} auth={isAuthenticated} /&gt;
          &lt;PrivateRoute exact path=&quot;/home&quot; component={ListUser} auth={isAuthenticated} /&gt;
        &lt;/Switch&gt;
      &lt;/Router&gt;
    );
  }
  
  export default App;
  </code></pre>
  <p><strong>login.js</strong></p>
  <pre><code>import React, { useEffect, useState } from 'react';
  import {useHistory} from 'react-router-dom';
  
  function Login() {
      const history = useHistory();
      const loginUser = (body) =&gt; {
          SetLoader(true);
          fetch('/api/v2/users/tokens', {
              method: 'POST',
              body: JSON.stringify(body),
              headers: {
                  'Content-Type': 'application/json',
              }
          })
              .then(response =&gt; {
                  SetLoader(false);
                  if (response.status == 200) {
                      SetError(false);   
                      cookie.set('authorization',response.headers.map.authorization,{path:'/'});
                      history.push('/');
                  }
                  else {
                      SetError(true);
                      StoreResponse(JSON.parse(response._bodyInit).message);
                  }
              })
              .catch((error) =&gt; {
                  console.error('Error:', error);
              });
      }
  }
  
  export default Login;
  </code></pre>