2017-05-30 1 views
0

Ich versuche, eine Anwendung mithilfe von React Native zu erstellen. Ich habe eine Registrierungsseite, aber es funktioniert nicht. Ich habe eine Methode check genannt, wenn das Passwort, um zu sehen und überprüfen Passwort der Benutzer schrieb gleich ist:Funktion wird automatisch aufgerufen und funktioniert nicht wie erwartet

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."); 
    } 
    } 

das Problem ist, dass ich im Protokoll sehen, dass die Funktion automatisch aufgerufen wird, immer wenn ich bekomme die Registrierungsseite. Dies ist das Protokoll:

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... 

und es läuft weiter ..

das erscheint, sobald ich in das Register Seite bekommen, plus, this.handlePress nicht genannt zu werden. dies ist 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") 
    }); 
    } 

und hier nenne ich die check Funktion:

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

Was mache ich falsch? Versuchen

Antwort

1

Try this:

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."); 
    } 
} 

Und versuchen, die onPress zu diesem zu ändern:

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

Danke, es funktioniert jetzt. –

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

Dank aber, check wird noch automatisch aufgerufen. –

Verwandte Themen