title: Can't perform a React state update on an unmounted component?
body: <p>I am fetching data in componentDidMount and updating the state and the famous warning is appearing:</p>
  
  <blockquote>
    <p>Can't perform a React state update on an unmounted component. This is
    a no-op, but it indicates a memory leak in your application. To fix,
    cancel all subscriptions and asynchronous tasks in the
    componentWillUnmount method.</p>
  </blockquote>
  
  <pre><code>state = {
      post: null
  }
  
  render() {
      console.log(this.props.postId)
      if (this.props.post) {
          return (
              &lt;div&gt;
                  &lt;h3&gt; {this.state.post.postTitle} &lt;/h3&gt;
                  &lt;p&gt; {this.state.post.postBody} &lt;/p&gt;
              &lt;/div&gt;
  
          );
      } else {
          return &lt;Redirect to="/blog" /&gt;
      }
  }
  componentDidMount() {
      this._isMounted = true;
      axios
          .get('https://jsonplaceholder.typicode.com/posts/' + + this.props.postId)
          .then((response) =&gt; {
              let post = {
                  id: response.data.id,
                  postTitle: response.data.title,
                  postBody: response.data.body
              }
              this.setState((prevState,props)=&gt;{
                  console.log('post',post)
                  console.log('prevState',prevState)
                  console.log('props',props)
              })
          })
          .catch((e) =&gt; {
              console.log('error', e)
          })
  }
  </code></pre>
  
  <p>}</p>
  
  <p>What is causing this warning and what is the best way to fetch the data and update the state?</p>