1

我有以下代码在我的异步函数结束后无法显示警报。

{
  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);
        }
      );
    }
  )
}

有什么线索吗?

4

2 回答 2

0

将警报移动到回调中setState

像下面这样

clientResponse => {
  this.setState({ isLoading: false }, 
                () => alert("Authenticated Successfully!"));
},
于 2019-03-20T12:49:40.293 回答
0

请记住,并非所有浏览器功能都可以在 React Native 中使用,您正在使用的警报API 就是这种情况。

如果你想要类似的功能,你应该尝试使用React Native 的 Alert 组件

于 2019-03-20T12:32:34.460 回答