undefined不是React-native函数

时间:2017-09-28 22:04:47

标签: javascript react-native

<TouchableOpacity onPress={() => this.login.bind(this).then(( )=> {this.navigate("Sikayet")})}  style={styles.button}>
    <Text style={styles.buttonText}>GİRİŞ</Text>
</TouchableOpacity>

when clicked it gives this error. What should I do?

1 个答案:

答案 0 :(得分:0)

请尝试使用此代码:

<TouchableOpacity
  onPress={() => {
    this.login().then(() => {
      this.navigate("Sikayet")
    })
  }}
  style={styles.button}>
  <Text style={styles.buttonText}>GİRİŞ</Text>
</TouchableOpacity>

或者,要在login功能中稍微清理一下,请在那里处理导航部分,如下所示:

// in render function:
<TouchableOpacity
  onPress={this.login.bind(this)}
  style={styles.button}>
  <Text style={styles.buttonText}>GİRİŞ</Text>
</TouchableOpacity>

// in login function:
login() {
  otherFunction(email, password).then(() => {
    this.navigate("Sikayet")
  }).catch(error => {
    // invalid login credentials
    alert('Invalid email and password')
  })
}