我有一个有趣的问题。
当我按下注册按钮时,以下功能在SignUp组件中调用。
//SignUp.js
signUpHandler = () => {
if (this.state.email == '' || this.state.password == '') {
alert("Email or Password is empty.")
}
else {
firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
.then(() => this.props.navigation.navigate('ExtendedRegisteration'))
.catch(error => { alert(error.message) });
}
}
现在,这不能导航到“ ExtendedRegisteration”,但是当我执行以下操作时,它就可以导航。
//SignUp.js
signUpHandler = () => {
if (this.state.email == '' || this.state.password == '') {
alert("Email or Password is empty.")
}
else {
this.props.navigation.navigate('ExtendedRegisteration')
}
}
这是Firebase的问题吗?使用Firebase注册后,我需要导航至“ ExtendedRegisteration”。
sign.Handler中this.props的输出:
Object {
"navigation": Object {
"addListener": [Function addListener],
"canGoBack": [Function canGoBack],
"dangerouslyGetParent": [Function dangerouslyGetParent],
"dangerouslyGetState": [Function anonymous],
"dispatch": [Function dispatch],
"goBack": [Function anonymous],
"isFocused": [Function isFocused],
"jumpTo": [Function anonymous],
"navigate": [Function anonymous],
"pop": [Function anonymous],
"popToTop": [Function anonymous],
"push": [Function anonymous],
"removeListener": [Function removeListener],
"replace": [Function anonymous],
"reset": [Function anonymous],
"setOptions": [Function setOptions],
"setParams": [Function anonymous],
},
"route": Object {
"key": "Sign Up-q-zIoH0VCp",
"name": "Sign Up",
"params": undefined,
},
}
''这意味着上下文,这是最有趣的反应。尝试console.log(this.props)来检查Firebase中的道具是否与另一个示例相同。由于从诺言内部调用了this,因此可以更改“ this”上下文。它发生的时间超过了预期的时间。
您可以尝试创建函数
constructor(props){
super(props);
this._onUserCreation = this._onUserCreation.bind(this);
}
_onUserCreation=()=>{this.props.navigation.navigate('ExtendedRegisteration')};
//SignUp.js
signUpHandler = () => {
if (this.state.email == '' || this.state.password == '') {
alert("Email or Password is empty.")
}
else {
firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
.then(() => this._onUserCreation())
.catch(error => { alert(error.message) });
}
}
无论您从哪里调用注册功能并使用该参数代替它,都可以将其作为参数传递。