title: Do I have to initialize the component state in both constructor() and componentWillReceiveProps()?
body: <p>In my <strong>React/Redux</strong> application, I trigger an API call in the index.js (The entry point) as I want the data to be available even before user navigates to the component. </p>
  
  <p>Actually, this approach helps to reduce the user's wait time as we'll have the data loaded before user reaches the component.</p>
  
  <p>In our use-case, we need to initialize the component state with the props (<code>props</code> are passed from store). I faced below issue in the approach.</p>
  
  <ul>
  <li><strong>case 1: Let's assume user has reached the component before the API
  returned that data.</strong> In this case, that particular store object will be
  empty and the props (which is passed from <code>react-redux</code> <code>connect</code>
  wrapper) will be undefined/null. So I need to render <code>"Loading.."</code>
  message. When the data arrives, we initialize the component state
  using <code>setState()</code> in <code>componentWillRecieveProps().</code></li>
  <li><strong>case 2: If data has arrived before user navigates to the component.</strong>
  For this case, We can either use <code>constructor()</code> or <code>componentWillMount()</code> to initialize the state from <code>props</code>, as <code>props</code> is having the data. I can't rely only on <code>componentWillRecieveProps()</code> as, it'll not execute during the initialization life cycle.</li>
  </ul>
  
  <p>So I ended up doing the same initialization steps in 2 places as component should handle both cases. Is this a right approach? or Is there any better approach to avoid these kind of DRY code.</p>
  
  <p>Thanks in Advance!!!</p>