title: When and how to redirect with Apollo Client and React Router
body: <p>lI have created a React component using Apollo and I currently use the render function to perform a redirect after data has loaded but I receive the warning: <code>Warning: Cannot update during an existing state transition (such as within</code>render<code>). Render methods should be a pure function of props and state.</code></p>
  
  <p>Here's my code:
  <a href="https://gist.github.com/jmn/c3f7c4489cd5f759808a62b48352ce87" rel="nofollow noreferrer">https://gist.github.com/jmn/c3f7c4489cd5f759808a62b48352ce87</a></p>
  
  <p>The redirect part:</p>
  
  <pre><code>render() {
      return (
        &lt;Query query={Q} variables={{ cursor: this.props.match.params.id }}&gt;
        {({ loading, error, data, fetchMore }) =&gt; {
          if (loading) return &lt;p&gt;Loading...&lt;/p&gt;;
          if (error) return &lt;p&gt;Error :(&lt;/p&gt;;
          if (!this.props.match.params.id) {
            this.props.history.push(
              "/post/" + data.allPosts.pageInfo.endCursor
            );
          }
          return (
            &lt;div&gt;&lt;/div&gt;
          )
  </code></pre>
  
  <p>How can I do this in idiomatic React code and avoid any warnings?</p>