【发布时间】:2023-03-30 22:56:01
【问题描述】:
我有一个注册用户功能,如下所示:
onRegisterUser = () => {
const { email, password, isLoading} = this.state;
const { navigation } = this.props;
registerUser(
email,
password,
() =>
this.setState({
isLoading: !this.state.isLoading,
}),
navigation
);
};
该函数从注册屏幕接收输入电子邮件,传递和 isLoading 状态并执行以下操作:
import { Alert } from "react-native";
import firebase from "./firebase";
import { newUser } from "./database";
export const registerUser = (email, password, toggleLoading) => {
toggleLoading();
const isInputBlank = !email || !password;
if (isInputBlank) {
Alert.alert("Enter details to signup!");
toggleLoading();
}
//If Everything OK Register User
else {
//CR: change to async-await
firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.then(() => {
newUser(firebase.auth().currentUser.uid);
})
.catch(function (error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode == "auth/weak-password") {
alert("The password is too weak.");
} else if (errorCode == "auth/invalid-email") {
alert("Email is Invalid");
} else if (errorCode == "auth/email-already-in-use") {
alert("Email is Already in use!");
} else {
alert(errorMessage);
}
console.log(error);
});
}
};
我的问题是 toggleLoading(); Inside if (isInputBlank) 没有做任何事情
如果出现错误(此示例中为空输入),我正在尝试更改 isLoading 状态,但它什么也不做,
它在一开始只工作一次,就是这样。
如果警报在我关闭时被激活,则加载屏幕仍然存在
我错过了什么?
【问题讨论】:
标签: reactjs react-native