【发布时间】:2016-11-21 20:43:56
【问题描述】:
号召性用语(后端调用)响应是一些数组 - 在此处未定义 - 在我映射数组的其他少数情况下,我也看到未定义错误的映射。 componentDidMount 是放置此类调用的正确位置吗?
当我在调度之前控制台登录操作创建者时,我得到了响应。
componentDidMount() {
this.props.fetchData(test, foo);
console.log(this.props.responseData); //getting here undefined
}
function mapStateToProps(state) {
return {
responseData: state.abc.responseData,
};
}
Mycomp.propTypes = {
responseData: React.PropTypes.array,
fetchData: React.PropTypes.func,
};
export default connect(mapStateToProps, actions)(Mycomp);
【问题讨论】:
-
大概
fetchData是异步的吧?所以它不会像那样在下一行可用 -
查看此问题并接受答案。我想你会发现它很有帮助stackoverflow.com/questions/39381378/…
标签: reactjs react-jsx react-redux