title: Can I call APIs in componentWillMount in React?
body: <p>I'm working on react for last 1 year. The convention which we follow is make an API call in <code>componentDidMount</code>, fetch the data and setState after the data has come. This will ensure that the component has mounted and setting state will cause a re-render the component but I want to know why we can't setState in <code>componentWillMount</code> or <code>constructor</code></p>
  
  <p>The official documentation says that : </p>
  
  <blockquote>
    <p>componentWillMount() is invoked immediately before mounting occurs. It
    is called before render(), therefore setting state in this method will
    not trigger a re-rendering. Avoid introducing any side-effects or
    subscriptions in this method.</p>
  </blockquote>
  
  <p>it says <code>setting state in this method will not trigger a re-rendering</code>, which I don't want while making an API call. If I'm able to get the data and able to set in the state (assuming API calls are really fast) in <code>componentWillMount</code> or in <code>constructor</code> and data is present in the first render, why would I want a re-render at all?</p>
  
  <p>and if the API call is slow, then <code>setState</code> will be async and <code>componentWillMount</code> has already returned then I'll be able to setState and a re-render should occur. </p>
  
  <p>As a whole, I'm pretty much confused why we shouldn't make API calls in constructor or componentWillMount. Can somebody really help me understand how react works in such case?</p>