title: How to efficiently fetch data from URL and read it with reactjs?
body: <p>I have some URL with json and need to read data.
  For the sake of this example json looks like this: </p>
  
  <pre><code>{
     "results": [
          ...
       ],
  
     "info": {
          ...
       }
  }
  </code></pre>
  
  <p>I want to return fetched data as a property of a component.
  What is the best way to do it?
  I tried to do that with axios. I managed to fetch data, but after setState in render() method I received an empty object. This is the code:</p>
  
  <pre><code>export default class MainPage extends React.Component {
  
  constructor(props: any) {
     super(props);
     this.state = {
         list: {},
         };
     }
  
     public componentWillMount() {
         axios.get(someURL)
         .then( (response) =&gt; {
             this.setState({list: response.data});
             })
         .catch( (error) =&gt; {
             console.log("FAILED", error);
          });
       }
  
     public render(): JSX.Element {
  
       const {list}: any = this.state;
       const data: IScheduler = list;
  
       console.log(data); // empty state object
  
       return (
          &lt;div className="main-page-container"&gt;
             &lt;MyTable data={data}/&gt;  // cannot return data
          &lt;/div&gt;
       );
     }
  }
  </code></pre>
  
  <p>I don't have a clue why in render() method the data has gone. If I put </p>
  
  <pre><code>console.log(response.data);
  </code></pre>
  
  <p>in .then section, I get the data with status 200.</p>
  
  <p>So I ask now if there is the other way to do that.
  I would be grateful for any help.</p>
  
  <p>----Updated----
  In MyTable component I got an error after this:</p>
  
  <pre><code>const flightIndex: number 
  = data.results.findIndex((f) =&gt; f.name === result);
  </code></pre>
  
  <p>Error is:</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'findIndex' of undefined
  </code></pre>
  
  <p>What's wrong here? How to tell react this is not a property?</p>