title: How to find object in array and show it in React component?
body: <p>I have array of <strong>cities</strong> with objects like this: </p>
  
  <pre><code>[{id: 1, name: 'New York'}, {id: 2, name: 'London'} ...]
  </code></pre>
  
  <p>and I have a value of <strong>id</strong>.</p>
  
  <p>I put elements (names) from array to select list. But I need to add first option with value from array (name) which have the corresponding id which I can't make it work.</p>
  
  <p>My component:</p>
  
  <pre><code>const propTypes = {  
    cities: PropTypes.array,  
    enteredEvent: PropTypes.array  
  };
  
  class newEvent extends Component {
    constructor(props) {
      super(props);
      this.state = {
        showInOption: ''
      };
      this.handleDictionary = this.handleDictionary.bind(this);
      this.searchTypeEvent = this.searchTypeEvent.bind(this);
    }
  
    componentDidMount() {
      this.searchTypeEvent();
    }
  
    handleDictionary(e) {
      ...
    }
  
    searchTypeEvent() {
      if (this.props.enteredEvent.cityid !== null &amp;&amp; this.props.enteredEvent.cityid !== undefined) { // if I have id value
        const type = this.props.cities.find(el =&gt; el.id === this.props.enteredEvent.cityid); // find an object with id
        this.setState({ showInOption: type.name });
      }
      this.setState({ showInOption: 'Select something' });
    }
  
    render() {
      return (
        &lt;div&gt;       
          &lt;select onChange={this.handleDictionary}&gt;
            &lt;option&gt;{this.state.showInOption}&lt;/option&gt; // here I need to add a value
            {this.props.cities.map(item =&gt; {   // here I call other options
              return (&lt;InputSelect key={item.id} directory={item}/&gt;);
            })}
          &lt;/select&gt;        
        &lt;/div&gt;
      );
    }
  }
  </code></pre>
  
  <p>I have an error:</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'name' of undefined</p>
  </blockquote>
  
  <p><strong>How can I fix it?</strong></p>