title: Call javascript function from ReactJS
body: <p>I am new to javascript and reactJS and I'm stuck. I have a javascript file where I make a REST call. The file looks like this:</p>
  
  <pre><code>var data;
  function getDataRequest() {
   const request = new XMLHttpRequest();
      request.open('GET', "localhost:8080/getData", true);
      request.onload = function () {
          var data = JSON.parse(this.response);
          if (request.status &gt;= 200 &amp;&amp; request.status &lt; 400) {
              products = data;
          } else {
              console.log('error');
          }
      };
      request.send();
  }
  var getDataList = function() {
      getDataRequest();
      return data;
  };
  getDataList();
  </code></pre>
  
  <p>And the file which contains the React component looks like this:</p>
  
  <pre><code>var = data;
  class Datas extends React.Component {
  
      render() {
          data = this.getDataList;
          return (
              &lt;DataTable data={data} /&gt;
          );
      }
  }
  export default Products;
  </code></pre>
  
  <p>The problem is that data in the React component remains 'undefined'. I am making the rest call in a different file because I want to call the rest call from multiple react components.</p>