【发布时间】:2020-10-02 17:06:54
【问题描述】:
代码如下:
const mapStateToProps = (state, ownProps) => {
const id = ownProps.match.params.id;
const sheets = state.firestore.data.sheets;
const sheet = sheets && sheets[id];
const rows = sheet.rows;
return {
rows: rows,
};
};
export default compose(
firestoreConnect(() => ["sheets"]),
connect(mapStateToProps)
)(Table);
数据结构:
sheets:[
filename:'abc.txt',
rows:[ {somedata} , {somedata} ]
]
在加载页面时,我可以加载行,但在重新加载时,我会丢失状态数据。这是错误:
TypeError:无法读取未定义的属性“行”
【问题讨论】:
-
可能是在 redux 数据准备好之前调用了 mapStateToProps 函数,因此您的嵌套搜索会触发“无法读取...未定义”错误。您在哪里提出数据请求?
标签: reactjs redux mapstatetoprops