React native React Native、Fetch和Dispatch:如何访问mapDispatchToProps()中的responseData?

React native React Native、Fetch和Dispatch:如何访问mapDispatchToProps()中的responseData?,react-native,react-redux,fetch,dispatch,React Native,React Redux,Fetch,Dispatch,我正在从我的“Scanner”组件获取componentWillMount()中的JSON数据,如下所示: async componentWillMount() { const url = 'https://foo.com/products/product1.json'; fetch(url) .then((response) => response.json()) .then((responseData) => this.props.dispatchProduct

我正在从我的“Scanner”组件获取componentWillMount()中的JSON数据,如下所示:

async componentWillMount() {
  const url = 'https://foo.com/products/product1.json';

  fetch(url)
  .then((response) => response.json())
  .then((responseData) => this.props.dispatchProductLoad())
  .catch(error => {
    console.log(error);
  });
}
下面是我的调度代码:

function mapDispatchToProps(dispatch) {
  return { dispatchProductLoad: () => dispatch(productLoad(SOMEDATA)) };
};

export default connect(null, mapDispatchToProps)(Scanner);
其中变量SOMEDATA应保存responseData中的值(目前尚未定义)


因此,我的问题是-如何将某些数据的值设置为responseData中保留的值?

您可以调用action creator,将
responseData
作为参数,并定义
mapDispatchToProps
函数,如

async componentWillMount() {
  const url = 'https://foo.com/products/product1.json';

  fetch(url)
  .then((response) => response.json())
  .then((responseData) => this.props.dispatchProductLoad(responseData))
  .catch(error => {
    console.log(error);
  });
}


function mapDispatchToProps(dispatch) {
  return { dispatchProductLoad: (response) => dispatch(productLoad(response)) };
};

export default connect(null, mapDispatchToProps)(Scanner);