title: Problems trying to return api data without a class
body: <p>I built an api that returns me the units that I have registered in a DB but when trying to return these are not reviewing</p>
  
  <pre><code>import React, { Component } from 'react';
  import axios from 'axios';
  
  const api = {
  
    units: () =&gt; {
      axios.get('http://192.168.0.23/api/public/api/units')
      .then(response =&gt; {
        console.log(response);
          return response.data.data
      }).catch((error) =&gt; { 
        console.log(error.message)
      });
      return 'Error'
    },
  
  };
  
  export default api;
  </code></pre>
  
  <p>The response displays the data correctly, the <code>response.data.data</code> if used in a file with a class I can set a state <code>units = []</code> and with a <code>setState</code> return the units</p>
  
  <p>However I would like to create this file for the api returns, however as I do not use a class so I understand I can not use the state.</p>
  
  <p>Is there any way of without the class returning this data, or keeping in a variable or something of the sort?</p>
  
  <p>Or use <code>setState</code> right here without a class?</p>
  
  <p>I believe that these would be the ways to solve my problem, but if someone else knows otherwise than putting the api call in the same file as the final class may be too.</p>
  
  <p>I tried that way too:</p>
  
  <pre><code>async function getUnits() {   
    return await axios.get('http://192.168.0.23/api/public/api/units');
  }
  
  getUnits.then((response) =&gt; {
    console.log(response);
      return response.data.data
  }).catch((response) =&gt; { 
    console.log(response)
  });
  </code></pre>
  
  <p>But the error indicated that <code>getUnits.then is not a function</code></p>
  
  <p>Even with a normal function did not work:</p>
  
  <pre><code>function units() {
    axios.get('http://192.168.0.23/api/public/api/units')
    .then(response =&gt; {
      console.log(response);
        return response.data.data
    }).catch((error) =&gt; { 
      console.log(error.message)
    });
    return 'Error'
  };
  </code></pre>