title: Calling functions from other components in react-native
body: <p>How can I call functions from other components in react-native ?</p>
  
  <p>I have this custom component which renders another component defined somewhere else and a image button. When tapping the image I want to call a function from the other component. When executing the example below I get <code>undefined is not an object (evaluating this.otherComponent.doSomething')</code></p>
  
  <pre><code>export default class MainComponent extends Component {
  
    _onPressButton() {
      this.otherComponent.doSomething();
    }
  
    render() {
      return (
        &lt;View style={styles.container}&gt;
          &lt;TagContainer style={styles.flow_container} ref={(instance) =&gt; this.otherComponent = instance}&gt;
          &lt;/TagContainer&gt;
          &lt;TouchableHighlight onPress={this._onPressButton}&gt;&lt;Image source={require('./img/ic_add.png')} style={styles.add_tags_button_view} /&gt;&lt;/TouchableHighlight&gt;
        &lt;/View&gt;
      );
    }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>export default class OtherComponent extends Component {
  
      addTag() {
          this.state.tags = this.state.tags.push("plm");
          console.log('success..');
      }
  
      ....
  }
  </code></pre>