How to call one of multiple functions - JavaScript?

后端 未结 2 1972
我在风中等你
我在风中等你 2020-12-18 17:23

I have three functions:

  1. Change Email
  2. Change password
  3. Change otherData

And One Button to call them , when the user changes his da

2条回答
  •  时光取名叫无心
    2020-12-18 18:08

    Please do the following:

    // You have to change the method _updateProfileData as following
    _updateProfileData = async () => {
            if (this.state.currentPassword === "") {
                alert("please write your current password first!")
                return;
            } if (this.state.currentUser.email === "") {
                alert("Email can't be blank")
                return;
            } if (this.state.currentUser.username === "") {
                alert("Username can't be blank")
                return;
            } if (this.state.currentUser.city === "") {
                alert("City can't be blank")
                return;
            } if (this.state.currentUser.mobileNumber === "") {
                alert("Mobile number can't be blank")
                return;
            } else {
                this._getCurrentUserData((oldUserData) => {
                if(oldUserData.email !== this.state.currentUser.email) {
                     await this.changeEmail();
                }
    
                if(this.state.newPassword !== this.state.currentPassword) {
                     await this.changePassword();
                }
    
                if(oldUserData.username !== this.state.currentUser.username || oldUserData.city !== this.state.currentUser.city || oldUserData.mobileNumber !== this.state.currentUser.mobileNumber ) {
                     await this._updateData();
                }
                );
            }
        }
    
    // You have to add this method in your component
    _getCurrentUserData = (callBack) => {
       AsyncStorage.getItem('@MyProfile:data')
                .then(json => JSON.parse(json))
                .then(currentUser => callBack(currentUser))
                .catch(error => console.log('@error' + error));
    }
    

提交回复
热议问题