title: TypeError: items is undefined while reading a json using fetch in reactjs
body: <p>This is the first time I'm working with APIs using ReactJS. I know the basics of reactjs pretty well but I'm unable to read the response. I've a json response from youtube api<a href="https://i.stack.imgur.com/CB9oy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CB9oy.png" alt="enter image description here"></a>.</p>
  
  <p>Initially i got </p>
  
  <blockquote>
    <p>TypeError: items.map is not a function.</p>
  </blockquote>
  
  <p>But then i realized that i might be getting an Object and not an array. I solved the problem by <code>items: json.statistics</code>. But now I'm getting other error i.e </p>
  
  <blockquote>
    <p>TypeError: items is undefined</p>
  </blockquote>
  
  <p>I just want to fetch 3 information viz <code>viewCount</code>, <code>subscriberCount</code> and <code>videoCount</code>. I've written this code</p>
  
  <pre><code>import React, {Component} from 'react';
  import './App.css';
  
  class App extends Component {
      constructor(props) {
          super(props);
          this.state = {
             items: [],
             isLoaded: false
          }
      }
  
      componentDidMount() {
          fetch('https://www.googleapis.com/youtube/v3/channels?part=statistics&amp;id=UCOYqNBjmWF8j-PzI7ZPjt_w&amp;key=AIzaSyAMeZQW6sUQgLdDTnMVeokfbcFcT2A9SuA')
          .then(res =&gt; res.json())
          .then(json =&gt; {
              this.setState({
                  isLoaded: true,
                  items: json.statistics
              })
          });
      }
  
      render() {
          var {isLoaded, items} = this.state;
          if(!isLoaded) {
                return (&lt;div&gt;Loading...&lt;/div&gt;)
          }
          else {
              return (
                  &lt;div&gt;
                     &lt;ul&gt;
                        {
                           items.map(item =&gt; (
                             &lt;li key={item.id}&gt;
                                Total views: {item.viewCount} 
                                Total subscribers: {item.subscriberCount}
                                Total videos: {item.videoCount}
                             &lt;/li&gt;
                          ))}
                      &lt;/ul&gt;
                  &lt;/div&gt;
              )
            }
        }
     }
  
      export default App;
  </code></pre>