title: Rendering redirect component based on ajax request
body: <p>I've got a home route '/' and whenever a user goes to that route I want to send him either to his page if he is authenticated or send him to '/login' route if he isn't authenticated. In order to send a user to his page I make a request to the server, fetch his id and redirect him to the route based on the id I get from the server. However I'm a bit confused as to how to implement that logic in my Home component correctly. What would be the best way to render redirect component based on the result of the ajax request?</p>
  
  <pre><code>class Home extends React.Component {
  
      async componentDidMount() {
          const response = await Api.getUserId();
          const id = response.data._id;
      }  
  
      render() {
          if(this.props.userStatus.authenticated) {
              return &lt;Redirect to={{
                  pathname: `/${id}`,
                  state: { from: this.props.location }
              }}/&gt;
          }
          return &lt;Redirect to={{
              pathname: '/login',
              state: { from: this.props.location }
          }}/&gt;
      }
  }
  
  export default connectComponent(['userStatus'], Home);
  </code></pre>