title: How to retrieve data from promise object in React JS
body: <p>I am trying to get data from an API. But the fetch result is returned as promise object. I want to return the contents from this promise to invoke react action.</p>
  
  <pre><code>let loginData = fetch(loginURL, { method : 'POST', headers : headerParams, 
   body: bodyParams })
    .then((response) =&gt; response.json())
    .then(data =&gt; {
      return data['retrieve-agent'];
  });
  console.log('loginData ===&gt;', loginData.agent);
  return {
    type: 'GET_AGENT_DETAILS',
    payload: loginData
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ya4LO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ya4LO.png" alt="enter image description here"></a></p>