title: react.js : fetched data is undefined outside of api folder
body: <p>I am trying to make a web application using Motorcycle Specs Database API from rapidAPI.</p>
  <p>I want to export fetched data from index.js to App.js so that I can use the data in the app. But, when I try to console.log the fetched data in componentDidMount function in App.js, it is undefined. I don't know why at the moment, can you see why??</p>
  <p>/api/index.js</p>
  <pre><code>import axios from &quot;axios&quot;;
  
  const options = {
    method: 'GET',
    url: 'https://motorcycle-specs-database.p.rapidapi.com/model/make-name/Yamaha',
    headers: {
      'X-RapidAPI-Host': 'motorcycle-specs-database.p.rapidapi.com',
      'X-RapidAPI-Key': 'MYAPIKEY'
    }
  };
  
  export const fetchData = async ()=&gt;{
      await axios.request(options).then(function (response) {
          console.log(response.data);
          return response.data;
      }).catch(function (error) {
          console.error(error);
      });
  
  }
  
  
  </code></pre>
  <p>App.js</p>
  <pre><code>import logo from './logo.svg';
  import './App.css';
  import {fetchData} from './api/index';
  import React, {Component} from 'react';
  
  class App extends React.Component{
    state = {
  
      data:[],
    }
  
    async componentDidMount(){
      const fetchedData = await fetchData();
      console.log('fetchedData is like this',fetchedData);
      this.setState({data:fetchedData});
    }
  
  
  render(){
    return (
      &lt;div className=&quot;App&quot;&gt;
        &lt;header className=&quot;App-header&quot;&gt;
          &lt;img src={logo} className=&quot;App-logo&quot; alt=&quot;logo&quot; /&gt;
          &lt;p&gt;
            Edit &lt;code&gt;src/App.js&lt;/code&gt; and save to reload.
          &lt;/p&gt;
          &lt;a
            className=&quot;App-link&quot;
            href=&quot;https://reactjs.org&quot;
            target=&quot;_blank&quot;
            rel=&quot;noopener noreferrer&quot;
          &gt;
            Learn React
          &lt;/a&gt;
        &lt;/header&gt;
      &lt;/div&gt;
    );
  }
  
  }
    
  
   
    
  
  export default App;
  
  
  </code></pre>