title: best place to fetch data before rendering in react
body: <p>I would like to know where I should fetch my data in the react life cycle.
  I tried to put my data in the <code>componentDidMount()</code>and <code>componenWillMount()</code>
  but without succes...</p>
  <pre><code>componentWillMount(){
     
   // this fetch the data from back-end set a store state with the payload
          this.props.fetchUser(); 
          this.setState({userData:this.props.auth});
  }
  
  //fetchMethod
  export const fetchUser = () =&gt; async dispatch =&gt;{//using redux-thunk
  
  
      const res= await axios.get('/api/current_user')
  
      dispatch({type:FETCH_USER, payload:res.data}); 
      
      
  
  };
  </code></pre>
  <p>in my render function I tried to use fetched userData by calling <code>this.state.userData</code>. but it's undefined. I also tried to get it by calling the correct store state, also without succcess. The thing I don't get is, according to my localstorage that store state is defined. Hope someone can tell me what I have done wrong.thanks!</p>