title: How to move the fetch api in react to a separate file
body: <p>I am calling an api from the component, since it looked ugly, thought of moving it out, this is what i tried:</p>
  
  <p>Before:(in the component)</p>
  
  <pre><code>fetch(url)
  .then(response =&gt; response.json())
  .then(data =&gt; this.setState({data, loading: false}));
  </code></pre>
  
  <p>After:</p>
  
  <p>Instead of putting the fetch in the component, i moved it to another function:</p>
  
  <pre><code>export function getData ( url) {
      fetch(url)
      .then(response =&gt; response.json())
      .then(data =&gt; {
          return data;
      })
  }
  </code></pre>
  
  <p>and i am calling 
  <code>getData(url)</code>
  from the component, but something is not right, i am not seeing any error, but it does not work </p>
  
  <p>Any thoughts ?</p>