足够简单的问题。我正在尝试读取此对象数组内的“ length”变量的值(请参见图1)
我的密码
const mapStateToProps = (state, ownProps) => {
const lecture = state.firestore.ordered.lectures;
const length = lecture.length;
return {
length: length,
}
}
答案 0 :(得分:0)
在写此问题时,我找到了解决方案:
解决方案代码
const mapStateToProps = (state, ownProps) => {
const length = state.firestore.ordered.lectures && state.firestore.ordered.lectures.length;
return {
length: length,
}
}