0

First of all i went through all the similar questions. couldn't find any answer that matches my case. so the main problem for me is, that async functions return Promise. and i'm trying to extract the 'true false' response. my code looks like this:

  async function isExistByUsername(username: string) {
    axios.get(`http://localhost:8080/users/isExistByUsername?username=${username}`)
      .then(response => {
        if (response.data){
          return true
        }else{
          return false
        }

      }).catch(error => alert(error.message));
  }

and i'm trying to validate on submit form like this:


const sendForm = async (e: any) => {
    e.preventDefault();

 let isValid: boolean = true; // just a boolean variable to stop the 

    if (isExistByUsername(user.username)) {
      isValid = false
   }
    if (isValid) {
      createUser(user)
    }

So if anyone could help me understand..

Thank you so much in advance guys!!

0 Answers0