title: How to fix "TypeError: Cannot read property 'length' of undefined" while render React Component
body: <p>I am trying to get and render data from api. In the render method of my Ticket component I've got the following error(see the render method):
  TypeError: Cannot read property 'length' of undefined.
  This code worked with a much similar example provided in the book but it doesn't work with my data(api is fine)</p>
  
  <pre><code>const CITY_API = 'http://api.travelpayouts.com/data/ru/cities.json',                  
          PROXY = 'https://cors-anywhere.herokuapp.com/'; 
  
  const getTickets = (url) =&gt; new Promise((resolves, rejects) =&gt; {
  const request = new XMLHttpRequest();
  request.open('GET', url);
  request.onload = () =&gt; (request.status === 200) ? 
      resolves(JSON.parse(request.response).results) :
      rejects(Error(request.statusText))
  request.onerror = err =&gt; rejects(err)
  request.send()
  })
  
  const Ticket = ({code}) =&gt; 
    &lt;div&gt;
      &lt;p&gt;{code}&lt;/p&gt;
    &lt;/div&gt;
  
  
  
  class TicketList extends Component {
  constructor() {
      super()
      this.state = {
          tickets: [],
          loading: false,
          error: null
      }
  }
  
  componentWillMount() {
      this.setState({loading: true});
      getTickets(PROXY + CITY_API)
          .then(tickets =&gt; {
              this.setState({tickets, loading: false});                            
          },
          error =&gt; {
              this.setState({error, loading: false});
          }
      )
  }
  
  componentWillUpdate() {
    console.log('updated');
  }
  
  render() {
      const  { tickets, loading, error } = this.state;
      return (
          &lt;div&gt;
              {(loading) ?
                  &lt;span&gt;Loading Tickets&lt;/span&gt; :                
                  (tickets.length) ?  //the line I'm getting the error
                      tickets.map((ticket, i) =&gt;
                          &lt;Ticket key={i} code={ticket.code} /&gt;
                      ) :
                      &lt;span&gt;No tickets is loaded...&lt;/span&gt;                                              
          }
          {(error) ? &lt;p&gt;Error&lt;/p&gt; : ""}
          &lt;/div&gt;
      ) 
    }
  }
  </code></pre>