2017-05-30 8 views
0

React Nativeを使用してアプリケーションを作成しようとしています。私は登録ページを持っていますが、動作しません。 私はパスワードかどうかを確認し、ユーザーが書いたパスワードを確認するためのcheckpasswordというメソッドを持って同じです。問題は、ログに私は私が取得するときに関数が自動的に呼び出さなっていることを見ることができるということです関数が自動的に呼び出され、正常に動作しない

checkPassword(){ 
    console.log("inside checkPassword"); 
    if (this.state.password == this.state.verify) { 
     console.log("inside if check..."); 
     this.handlePress; 
    }else{ 
     console.log("password not match."); 
    } 
    } 

登録ページ。これはログです:

RegisterScreen.js:23 inside checkPassword 
RegisterScreen.js:25 inside if check... 
RegisterScreen.js:23 inside checkPassword 
RegisterScreen.js:25 inside if check... 
RegisterScreen.js:23 inside checkPassword 
RegisterScreen.js:25 inside if check... 

、それはいっている。..

これはすぐに私はレジスタページに入るとして表示され、プラス、this.handlePressは呼び出され得ていません。これはhandlePressです:

handlePress(){ 
    firebaseRef.auth().createUserWithEmailAndPassword(this.state.email, this.state.password).then(function(newUser){ 
     //good 
     console.log("good") 
    }).catch(function(error){ 
     //bad 
     console.log("bad") 
    }); 
    } 

と、ここで私はのcheckpassword関数を呼び出す:

<TouchableOpacity style={styles.subButtom} onPress={this.checkPassword}> 
    <Text style={styles.subTxt}> 
    Register 
    </Text> 
    </TouchableOpacity> 

私が間違って何をしているのですか?

答えて

1

をお試しください:

checkPassword(){ 
    console.log("inside checkPassword"); 
    if (this.state.password == this.state.verify) { 
    console.log("inside if check..."); 
    this.handlePress(); 
    }else{ 
    console.log("password not match."); 
    } 
} 

を、あまりにもこれにたonPressを変更しよう:

<TouchableOpacity style={styles.subButtom} onPress={() => this.checkPassword()}> 
+0

ありがとうございます、今すぐ作業中です。 –

0

このお試しください

checkPassword(){ 
    console.log("inside checkPassword"); 
    if (this.state.password == this.state.verify) { 
     console.log("inside if check..."); 
     return this.handlePress(); 
    }else{ 
     console.log("password not match."); 
    } 
    } 
+0

おかげではなく、のcheckpasswordはまだ自動的に呼び出されます。 –

関連する問題