Ad

React Native Alert Function

- 1 answer

I want to show the alert function when I press the continue button. But I have an error. I want to put an alert function inside my onPress touchableOpacity. This is my code.

export default class Rate extends Component {
 render() {
    }
return (
          <TouchableOpacity
      activeOpacity={0.7}
      style={styles.button}
      onPress={() => 
        firebase.database().ref(list.title).set({Ratings : (this.state.Default_Rating)})
        alert('Thank you')
    }> 
      <Text>Continue</Text>
    </TouchableOpacity>

  </View>
);  }}
Ad

Answer

Your render method should be like as below and add one more bracket in onPress of TouchableOpacity

 render() {
    return (
          <TouchableOpacity
          activeOpacity={0.7}
          style={styles.button}
          onPress={() => {
            firebase.database().ref(list.title).set({Ratings : 
      (this.state.Default_Rating)})
            alert('Thank you')
        }
        }> 
          <Text>Continue</Text>
        </TouchableOpacity>
        );
       }
Ad
source: stackoverflow.com
Ad