title: react-native open modal automatically when state is changed
body: <p>I am using <a href="https://github.com/maxs15/react-native-modalbox" rel="nofollow noreferrer">react-native-modalbox</a>. What I want to do is open modal automatically when state is changed rather than using a button.</p>
  
  <p>Below is my code it works fine with the button. But I want the modal to open when <code>stateChange</code> state is changed.</p>
  
  <pre><code>import React from 'react';
  import Button from 'react-native-button';
  import Modal from 'react-native-modalbox';
  import {Text, StyleSheet, ScrollView, View, Dimensions, TextInput} from 'react-native';
  var screen = Dimensions.get('window');
  
  export default class TestScreen extends React.Component {
  
    constructor() {
      super();
      this.state = {
        isDisabled: false,
        number:''
  
  //I want to open modal when this state is changed
  
        stateChange:''
      };
    }
  
    render() {
  
      return (
        &lt;View style={styles.wrapper}&gt;
  
  // When I press this button it opens a modal  
  
          &lt;Button onPress={() =&gt; this.refs.modal3.open()} style={styles.btn}&gt;Position centered + backdrop + disable&lt;/Button&gt;
  
          &lt;Modal style={[styles.modal, styles.modal3]} position={"center"} ref={"modal3"} isDisabled={this.state.isDisabled}&gt;
            &lt;Text style={styles.text}&gt;Modal centered&lt;/Text&gt;
            &lt;Button onPress={() =&gt; this.setState({isDisabled: !this.state.isDisabled})} style={styles.btn}&gt;Disable ({this.state.isDisabled ? "true" : "false"})&lt;/Button&gt;
          &lt;/Modal&gt;
  
        &lt;/View&gt;
      );
    }
  }
  </code></pre>
  
  <p><strong>Edited</strong></p>
  
  <p>I want to use react lifecycle method to listen to this update and automatically update it. So I am using <code>componentDidUpdate</code>. I want to update <code>this.state.number</code> when ever <code>mobx</code> store is updated. However, the code below wouldn't work.</p>
  
  <pre><code>componentDidUpdate(nextProps, nextState) {
      this.setState({number:store.requestObject.number},
      console.log(this.state.number), 'state changed')
    }
  </code></pre>