React Native,Redux和Fetch:"可能的未处理承诺拒绝(id:0)"

时间:2018-02-27 05:18:01

标签: javascript react-native redux

我正在将JSON数据从网页加载到我的React Native应用程序中,并希望将数据存储在Redux中。我现在正在使用Fetch:

fetch('https://foo.com/product-data/product1.json')
.then((response) => response.json())
.then((responseData) => this.state.productLoad(responseData)); 

其中productLoad是我的操作的名称:

export const productLoad = (productData) => {
  return {
    type: 'product_load',
    payload: productData
  };
};

不幸的是,当我运行Fetch代码时,我收到了这个错误:

  

可能的未处理承诺拒绝(id:0)   
  TypeError:_this2.state.productLoad不是函数

我一直在网上搜索,尝试一切,但无法找到解决方案。我倾向于认为它可能与在加载数据之前尝试调用操作有关,因此我尝试使用Redux Thunk,但没有运气(也许我只是没有正确配置Thunk) 。或者我的productLoad函数调用格式不正确?

我很感激任何想法和建议。

1 个答案:

答案 0 :(得分:1)

错误告诉我们this.state不包含productLoad函数。您可以使用productLoad操作将其导入到获取操作的文件。

相关问题