title: Reactjs get data with async on componentDidMount
body: <p>What I trying to do is, get user data before render, I made a object call API, it get data from api with axios (it get successfull) now I want to get it on info.js compontent, so I call it on componentDidMount:</p>
  
  <p><strong>API.js</strong></p>
  
  <pre><code>const API = {
    async getUser() {
      const cookies = new Cookies();
      const token = cookies.get('token');
      let result = null;
  
      if (token) {
        await axios.get('http://localhost:8000/api/user').then(res =&gt; {
          if (res.data.success) {
            result = res.data.success;
          }
        });
        return await result;
      } else {
        return false;
      }
    }
  };
  </code></pre>
  
  <p><strong>Info.js</strong></p>
  
  <pre><code>import API from 'API'
  
  export default class UserInfo extends React.Component {
      constructor() {
          super();
          this.state = {result: null};
      }
  
      componentDidMount() {
          let result = API.getUser();
          this.setState({
              result: result
          });
          console.log(result)
      }
  
      render() {
          return(
              &lt;div className="UserInfo"&gt;
                  {this.state.result}
              &lt;/div&gt;
          )
      }
  }
  </code></pre>
  
  <p>But it give me this:</p>
  
  <pre><code>Promise {&lt;pending&gt;}...
  </code></pre>
  
  <p>So I confused, what I have done wrong?</p>