簡體   English   中英

undefined不是一個函數React-native

[英]undefined is not a function React-native

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

單擊時會出現此錯誤。 我該怎么辦?

嘗試使用此代替:

<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')
  })
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2025 STACKOOM.COM