我有一个登录表单,填写此表单时,我希望将值存储在DB中,然后它将导航至确认页面。 问题是存储了空白值
PS:在没有DB插入功能的情况下,通过传递值的导航工作正常。
userLogin(email, password) {
firebase.database().ref('users/').set({
userEmail: email,
userPass: password,
}).catch((error)=>{
console.log('error ' , error)
});
}
<Button
title="Go to Details"
onPress = {this.userLogin(this.state.email, this.state.password),
this.props.navigation.navigate('Details', {
email: this.state.email,
password: this.state.password,
title: "Details Screen",
})
}
/>
答案 0 :(得分:0)
userLogin = (email, password) =>{
this.setState({
loading:true
})
try {
if(this.state.password.length >= 6){
firebase.auth().signInWithEmailAndPassword(email,password).then(response =>{
this.props.navigation.navigate('Details');
}).catch(error => {
alert("Email or password is incorrect");
this.setState({
loading: false
})
})
}else{
alert("Password must be more than 6 characters")
this.setState({
loading: false
})
return;
}
} catch (error) {
console.log(error.toString())
}
}
<Button title="Go to Details" onPress={()=>this. userLogin(this.state.email, this.state.password)} />