I am using react-native-modalbox. What I want to do is open modal automatically when state is changed rather than using a button.
Below is my code it works fine with the button. But I want the modal to open when stateChange state is changed.
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 (
<View style={styles.wrapper}>
// When I press this button it opens a modal
<Button onPress={() => this.refs.modal3.open()} style={styles.btn}>Position centered + backdrop + disable</Button>
<Modal style={[styles.modal, styles.modal3]} position={"center"} ref={"modal3"} isDisabled={this.state.isDisabled}>
<Text style={styles.text}>Modal centered</Text>
<Button onPress={() => this.setState({isDisabled: !this.state.isDisabled})} style={styles.btn}>Disable ({this.state.isDisabled ? "true" : "false"})</Button>
</Modal>
</View>
);
}
}
Edited
I want to use react lifecycle method to listen to this update and automatically update it. So I am using componentDidUpdate. I want to update this.state.number when ever mobx store is updated. However, the code below wouldn't work.
componentDidUpdate(nextProps, nextState) {
this.setState({number:store.requestObject.number},
console.log(this.state.number), 'state changed')
}