React 原生 Firebase 身份验证错误处理
React Native Firebase authentication error handling
如何在 Firebase 身份验证的错误处理函数中设置状态('this.setState({})')
?
它在 React Native 中不起作用。
onSignUpPress() {
if (this.state.password !== this.state.passwordConfirmation ) {
return this.setState({errorMessage: 'Your passwords do not match'});
}
ref.createUser({
email : this.state.email,
password : this.state.password
}, function(error, authData) {
if (error) {
console.log(error);
// this.setState({errorMsg: error}) <-- Like this, it not work on React Native.
} else {
console.log("Successfully created user account with uid:", userData.uid);
}
});
}
});
尝试使用 es6 胖箭头语法重写函数。上面的代码中肯定的一个问题是this
没有绑定到正确的范围。尝试像这样编写函数:
onSignUpPress() {
if (this.state.password !== this.state.passwordConfirmation ) {
return this.setState({errorMessage: 'Your passwords do not match'});
}
ref.createUser({
email : this.state.email,
password : this.state.password
},(error, authData) => {
if (error) {
console.log(error);
this.setState({errorMsg: error})
} else {
console.log("Successfully created user account with uid:", userData.uid);
}
});
}
})
相关文章:
- javascript:如何在antlr生成的Lexer中进行错误处理
- 生成pdf或其他非html文件时的错误处理
- sailsjs在创建两个模型时的错误处理
- 为什么没有调用我的流错误处理程序
- 错误处理try&catch+回调
- EventSource中的错误处理
- Angular JS中的通用Ajax错误处理-拦截器
- Sinon Mocha节点错误处理
- 如果文件不存在,fs.watch是否有错误处理程序
- Javascript初始化和错误处理
- AngularJS错误处理:根据错误数组显示错误
- JQuery 图像错误处理
- BreezeJS中央错误处理程序和自动重试
- 文件下载html与错误处理FileNotFound
- 使用mongoose保存多个文档时的错误处理
- Node.js如何知道回调的第一个参数是否是错误处理程序
- Meteor JavaScript-错误处理
- AJAX自定义错误处理代码问题
- 正在获取丢失的错误处理程序套接字消息,无法读取属性'timerID'使用Node.js和Socket.i
- 为什么不't JavaScript库使用错误处理