1

我在使用 Jsx 时遇到了这个奇怪的问题,当我想打印我的响应项目时它可以工作,并且我看到它在那里并持有一个值,但是当我尝试将它分配为状态时它说它是未定义的

getUserAsync(this.state.Email)
//Console.log display the data no problem!! typeof String.
        .then(resp =>{ console.log(resp.Hub.Data)}) //Works!!!
        .then((resp => {
          this.setState({
//Below I get ERROR Unhandled Rejection (TypeError): Cannot read property 'Hub' of undefined
            CSQReadings: resp.Hub.Data, //ERRPR???
          });
        }))

知道为什么要这样做吗?

4

1 回答 1

1

如果您不转换数据或从第一个返回值,请删除您的一个 .then 语句。

getUserAsync(this.state.Email)
      //Console.log display the data no problem!! typeof String.
      .then((resp => {
      this.setState({
            CSQReadings: resp.Hub.Data,
      });
  }))
于 2020-01-09T04:56:00.630 回答