I'm doing a major refactor on my meditation app and the problem I cannot resolve involves JSON .then function.
After adding validating conditions to my signup form (password length, email and username) my .then function which was closing the sign up form window stopped executing and I have no idea why ;/.
Could you give me a hand here please?
addUser = (event) => {
event.preventDefault();
if (this.state.username.length < 9) {
this.setState ({
showUsernameSignupError: 'block'
})
} else if ((this.state.email.length < 7) || (this.state.email.indexOf('@') === -1)) {
this.setState ({
showEmailSignUpError: 'block'
})
}
else if ( this.state.password.length < 7) {
this.setState({
showPasswordSignUpError: 'block'
})
}
else {
fetch('http://localhost:3000/users', {
method: "POST",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
body: JSON.stringify({
'username': this.state.username,
'email': this.state.email,
'password': this.state.password
})
}).then(() => {
this.setState({
signUpWindowVisible: false
})
})}
};
Aucun commentaire:
Enregistrer un commentaire