In my React Native app, I have the following constructor:
constructor(props) {
this.state = {flag: false}
}
and a <TouchableOpacity> that triggers a callback like this:
<TouchableOpacity
onPress={() => {
this.props.function1();
this.setState({flag: true})
}}
/>
function1() changes a prop that I'm getting from Redux:
function mapStateToProps (state) {
return {
var1: state.var1
}
}
The problem is that whenever function1() fires, my constructor gets called again, so flag gets reset to false. I need it to stay as true. What can I do here?
EDIT: I have the following Modal that gets switched on and off with flag:
<Modal
visible={this.state.flag}
/>