简体   繁体   English

React java 脚本:IF 函数仅在单击按钮时起作用一次

[英]React java script: IF function works only once on button click

So I am using react native, and firebase db.所以我使用 react native 和 firebase db。

On register form button click i have function which creates user and also upload some info like city phone lalala:在注册表单按钮上单击我有创建用户并上传一些信息的功能,如城市电话拉拉拉:

   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);
                                };
   };

So first time function works.所以第一次功能有效。 any of these IFS.这些 IFS 中的任何一个。 if I leave blank input I see error message nicely, but if I press button one more time it is just creating user anyway, even with empty values... like literaly this all works only once...如果我留下空白输入,我会很好地看到错误消息,但是如果我再按一次按钮,它仍然只是在创建用户,即使是空值......就像字面上一样,这一切都只工作一次......

Here is my create user function:这是我的创建用户功能:


   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);
                                };
   };

Maybe it is because of ASYNC and AWAIT?也许是因为 ASYNC 和 AWAIT? Im using in only because of tutorial, im not sure what is that.我只是因为教程而使用,我不确定那是什么。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM