React Native conditional state in onPress render any time without press component

3.9k Views Asked by At

Why is this onPress activated at any time without pressing TouchableOpacity when I change any property of state if project_id is not null?

<TouchableOpacity
  onPress={() => {
    if (this.state.feedback.project_id != null) {
      this.setModalVisible(true);
    } else {
      Alert.alert('Select a project please');
    }
  }}>
  <View>
    <Text>SEND NOW</Text>
  </View>
</TouchableOpacity>

Example process:

  1. I press this touchable and project_id == 1 , modal will open.
  2. I close the modal
  3. I change feedback.name with a textinput
  4. Because project_id is still 1 modal will open
0

There are 0 best solutions below