【问题标题】:Bluebird, returning data but getting new promise created but not returned... react/redux蓝鸟,返回数据但创建了新的承诺但没有返回......反应/redux
【发布时间】:2017-10-25 05:11:55
【问题描述】:

我似乎一直遇到同样的问题,我得到同样的错误:

A new promise was created but was not returned

我在 .then 块的末尾返回数据,但是似乎无法弄清楚我做错了什么。我什至只是遇到了这个问题并复制了代码,但似乎遇到了同样的错误。

componentDidMount() {
    if (this.props.user.currentUser == null) {
      this.props
        .currentUser()
        .then(data => {
          console.log(data);
          return data;
        })
        .catch(err => {
          return err;
        });
    }
  }

【问题讨论】:

  • 为了自己的充实,不再需要蓝鸟。 ES6 的标准中包含了 Promise。

标签: javascript reactjs promise redux bluebird


【解决方案1】:

这是从另一个被抛出的承诺中发生的。我只有return 而不是return null。我知道这可能不能直接回答这个严格的案例,但它对我有用。

这只是我认为会有所帮助的东西。所以如果你遇到这个问题,你发现自己有一个承诺链并且有

.then(() => {
  return;
})

把这个改成

.then(() => {
  return null;
})

它应该清除该警告。 Bluebird 说只有在你知道自己在做什么的情况下才使用它,但是如果它创建了奇怪的代理代码,我会重新考虑你如何使用你的承诺。

【讨论】:

    【解决方案2】:

    从未尝试过 react/redux,但返回实际的 promise 是否有效? '返回 this.props'

    componentDidMount() {
        if (this.props.user.currentUser == null) {
          return this.props
            .currentUser()
            .then(data => {
              console.log(data);
              return data;
            })
            .catch(err => {
              return err;
            });
    }
    

    }

    【讨论】:

      猜你喜欢
      • 2016-08-23
      • 2016-09-20
      • 1970-01-01
      • 2016-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-10
      相关资源
      最近更新 更多