Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React java脚本:如果函数只在按钮上工作一次,请单击_Javascript_Firebase_React Native_Firebase Authentication_Expo - Fatal编程技术网

Javascript React java脚本:如果函数只在按钮上工作一次,请单击

Javascript React java脚本:如果函数只在按钮上工作一次,请单击,javascript,firebase,react-native,firebase-authentication,expo,Javascript,Firebase,React Native,Firebase Authentication,Expo,所以我使用react native和firebase db 在“注册表单”按钮上,单击“我拥有”功能,该功能创建用户并上传一些信息,如城市电话LaLaLaLa: handleSignUp = () => { Fire.shared.createUser(this.state.email, this.state.password, this.state.name, this.state.avatar, this.state.mobile, this.state.pickerSe

所以我使用react native和firebase db

在“注册表单”按钮上,单击“我拥有”功能,该功能创建用户并上传一些信息,如城市电话LaLaLaLa:

   handleSignUp = () => {
    Fire.shared.createUser(this.state.email, this.state.password, this.state.name, this.state.avatar, this.state.mobile, this.state.pickerSelection, this.state.errorMessage)

    if (this.state.name == "") this.setState({ errorMessage: "Vartotojo vardas privalomas" });
        else  if (this.state.email == "") this.setState({ errorMessage: "El. pašto adresas privalomas" });
            else if (this.state.password == "") this.setState({ errorMessage: "Slaptažodis privalomas" });
                else  if (this.state.password2 == "") this.setState({ errorMessage: "Pakartokite slaptažodį" });
                    else  if (this.state.city == "") this.setState({ errorMessage: "Telefono nr. privalomas" });    
                        else  if (this.state.mobile == "") this.setState({ errorMessage: "Miestas privalomas" });    
                             else if ( this.state.password != this.state.password2) this.setState({ errorMessage: "Slaptažodžiai nesutampa" });
                                else { 
                                    Fire.shared.createUser(this.state.email, this.state.password, this.state.name, this.state.avatar, this.state.mobile, this.state.pickerSelection);
                                };
   };
所以第一次函数起作用。任何这些如果。若我保留空白输入,我会很好地看到错误消息,但若我再按一次按钮,它只是创建用户,即使是空值。。。就像字面上说的,这一切只会发生一次

以下是我的创建用户功能:


   handleSignUp = () => {
    Fire.shared.createUser(this.state.email, this.state.password, this.state.name, this.state.avatar, this.state.mobile, this.state.pickerSelection, this.state.errorMessage)

    if (this.state.name == "") this.setState({ errorMessage: "Vartotojo vardas privalomas" });
        else  if (this.state.email == "") this.setState({ errorMessage: "El. pašto adresas privalomas" });
            else if (this.state.password == "") this.setState({ errorMessage: "Slaptažodis privalomas" });
                else  if (this.state.password2 == "") this.setState({ errorMessage: "Pakartokite slaptažodį" });
                    else  if (this.state.city == "") this.setState({ errorMessage: "Telefono nr. privalomas" });    
                        else  if (this.state.mobile == "") this.setState({ errorMessage: "Miestas privalomas" });    
                             else if ( this.state.password != this.state.password2) this.setState({ errorMessage: "Slaptažodžiai nesutampa" });
                                else { 
                                    Fire.shared.createUser(this.state.email, this.state.password, this.state.name, this.state.avatar, this.state.mobile, this.state.pickerSelection);
                                };
   };

也许是因为异步和等待?我在中使用只是因为教程,我不确定那是什么。

你调用Fire.shared.createUser()两次,第一次是在你的检查之前(所以它无论如何都会创建用户),第二次是在你的检查通过时

你能解释一下这个函数是如何调用的吗?哦,是的。我明白了,对不起。我抄了,忘了删除:D谢谢你的回答!!!!