【问题标题】:Can't read length of array in JSX (React-Redux)无法读取 JSX 中数组的长度(React-Redux)
【发布时间】:2020-08-06 22:22:47
【问题描述】:

足够简单的问题。我正在尝试读取此对象数组中“长度”变量的值(参见图 1)

我的代码

const mapStateToProps = (state, ownProps) => {

    const lecture = state.firestore.ordered.lectures;
    const length = lecture.length;

    return {

        length: length,

    }
}

【问题讨论】:

    标签: arrays react-redux mapstatetoprops


    【解决方案1】:

    在写这个问题时,我找到了解决方案:

    解决方案代码

    const mapStateToProps = (state, ownProps) => {
    
    
        const length = state.firestore.ordered.lectures && state.firestore.ordered.lectures.length;
    
    
    
        return {
    
            length: length,
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-12
      • 2021-08-12
      • 2018-06-14
      • 2021-11-29
      • 2020-06-06
      • 2021-08-15
      • 1970-01-01
      • 2018-02-10
      相关资源
      最近更新 更多