title: React - how to use redirect inside hook useEffect?
body: <p>I'm trying to redirect a user who is not logged in to my application to the login page, and I have some conditions inside a useEffect that is inside my routes file, but when I enter one of them the redirect doesn't work and I want to know if it's something related to react-router-dom</p>
  <p>the Route.js file code below:</p>
  <pre><code>import React, { useEffect } from 'react'; // nao estava
  import { PropTypes } from 'prop-types';
  import { Route, Redirect, useHistory } from 'react-router-dom';
  
  import AuthLayout from '../pages/_layouts/auth';
  import DefaultLayout from '../pages/_layouts/default';
  
  import { store } from '../store';
  
  export default function RouteWrapper({
    component: Component,
    isPrivate,
    ...rest
  }) {
    const { signed } = store.getState().auth;
    const { googleSigned } = store.getState().googleAuth;
  
    const history = useHistory();
  
    useEffect(() =&gt; {
      if (!signed &amp;&amp; !googleSigned &amp;&amp; isPrivate) {
        return &lt;Redirect to=&quot;/&quot; /&gt;;
      }
  
      if ((signed &amp;&amp; !isPrivate) || (googleSigned &amp;&amp; !isPrivate)) {
  
        return &lt;Redirect to=&quot;/dashboard&quot; /&gt;;
  
      }
  
      return &lt;Redirect to=&quot;#&quot; /&gt;;
    }, [googleSigned, signed]);
  
    const Layout =
      signed || googleSigned || window.location.pathname === '/dashboard'
        ? DefaultLayout
        : AuthLayout;
  
    return (
      &lt;Route
        {...rest}
        render={(props) =&gt; (
          &lt;Layout&gt;
            &lt;Component {...props} /&gt;
          &lt;/Layout&gt;
        )}
      /&gt;
    );
  }
  
  RouteWrapper.propTypes = {
    isPrivate: PropTypes.bool,
    component: PropTypes.oneOfType([PropTypes.element, PropTypes.func])
      .isRequired,
  };
  
  RouteWrapper.defaultProps = {
    isPrivate: false,
  };
  
  </code></pre>
  <p>signed and googleSigned are states present in a reducer, the focus is google signed because the signed which is obtained using normal login is not implemented yet and the google signed is implemented using oAuth in the backend of the application</p>
  <p>the flow of my application at this moment is as follows the user clicks the login button on google is redirected to the google authentication screen and if the user is registered in the application he is redirected to the dashboard page, the dashboard page and dispatch a action that checks if the user is logged in to the application, the purpose is that if the user is not logged in (googleSigned = false) he is redirected back to the login page</p>