0

I need to call from my function "RegisterTaster" to my function "endRegisterAlert" but actually im not using constructor because i use the class like a const in react native.

How can i call the function ?

const Validator=(props)=>{

  async function RegisterTaster(){
    //do something...
    endRegisterAlert();
  }

  function endRegisterAlert(){
   //do something
  }

 return(
    <Button onPress={async ()=> await RegisterTaster() }> 
                    <Text >Register</Text> 
    </Button
  );
 }

export default Validator;

2 Answers 2

1

Just do this.

const Validator=(props)=>{

  async function RegisterTaster(){
    //do something...
    endRegisterAlert();
  }

  function endRegisterAlert(){
   //do something
  }

 return(
    <Button onPress={RegisterTaster}> 
                    <Text >Register</Text> 
    </Button
  );
 }
Sign up to request clarification or add additional context in comments.

Comments

0

You are using a function-based React Component.

Everything is right except for the part that you are awaiting an async function.

Do it this way:

return(
  <Button onPress={RegisterTaster}> 
     <Text>Register</Text> 
  </Button
);

OR:

return(
  <Button onPress={() => RegisterTaster()}> 
     <Text>Register</Text> 
  </Button
);

Either way, it should work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.