1

I have the following code which is not working to show an alert after my async function ends.

{
  new BaseService().request(
    serviceURL,
    "POST",
    headerParams,
    bodyParams,
    serverResponse => {
      this.setState({ isLoading: true });

      AuthenticationService.completeAuthentication(
        serverResponse,
        clientResponse => {
          this.setState({ isLoading: false }); // THIS WORKS AND HIDES LOADER
          alert("Authenticated Successfully!"); //THIS DOESN'T SHOW UP AN ALERT
        },
        error => {
          alert(error);
        }
      );
    }
  )
}

Any leads?

Krupal Ghorpade
  • 137
  • 1
  • 15

2 Answers2

0

Remember that not all browser functionalities will work in React Native, and that's the case for the alert API that you are using.

If you want a similar functionality, you should try with React Native's Alert component instead

sebbab
  • 847
  • 8
  • 13
0

Move the alert into the callback of setState

like bellow

clientResponse => {
  this.setState({ isLoading: false }, 
                () => alert("Authenticated Successfully!"));
},
adiga
  • 34,372
  • 9
  • 61
  • 83
AFLAH ALI
  • 451
  • 5
  • 17
  • Ok, just one more suggestion. Use an Alert.aler with an OK Bytton and move the setstate statement to onClick of the OK Button.. – AFLAH ALI Mar 20 '19 at 14:27