title: Setting State in a Callback inside of componentDidMount
body: <p>I'm currently using React 16.3(React Native), written <a href="https://reactjs.org/blog/2018/03/29/react-v-16-3.html" rel="nofollow noreferrer">here</a>, it suggests that I <em>SHOULD</em> be making any async requests inside of componentDidMount instead of componentWillMount because that will soon be deprecated.</p>
  
  <p>Unfortunately I'm getting a no-op warning as I'm trying to fetch data inside of componentDidMount, setting the data returned from my axios request as my state.</p>
  
  <p>Here's a snippet —</p>
  
  <pre><code>export default class MyComponent extends Component {
      state = {
        myData: []
      }
  
      componentDidMount() {
        axios.get('api-endpoint')
        .then(res =&gt; this.setState({ myData: res.data })
      }
      render() { return &lt;View&gt;...&lt;/View&gt; }
  }
  </code></pre>
  
  <p>and the warning —</p>
  
  <pre><code>Warning: Can only update a mounted or mounting component. 
  This usually means you called setState, replaceState, or 
  forceUpdate on an unmounted component. This is a no-op.
  
  Please check the code for the MyComponent component.
  </code></pre>