如何修复“无法读取未定义的属性'x'?

时间:2018-06-19 09:45:49

标签: reactjs redux

我是使用react和redux进行开发的新手,现在我想说我对一切都是如何连接有所了解。我也尝试尽可能多地修复自己的东西,但今天我遇到了一个我无法自行解决的错误。

这是我的组件

它正确连接到我的redux存储,并且还可以调度操作并完美地返回数据。

import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as matchActions from '../actions/matchActions';

/**
 * 
 */
class Match extends React.Component {

    componentDidMount() {
        this.props.actions.fetchMatch(this.props.match.params.matchid);
    }

    /**
     * Renders the component.
     */
    render() {
        return (
            <React.Fragment>

            </React.Fragment>
        )
    }
}

/**
 * Exposes a part of the redux store to this component.
 * 
 * @param {*} reduxStore The entire redux store.
 * @param {*} ownProps The properties which are being passed down from the parent component.
 */
const mapStateToProps = (reduxStore, ownProps) => {
    console.log('data => ', reduxStore.matchReducer.match.all_word_counts); // this one works
    console.log('data => ', reduxStore.matchReducer.match.all_word_counts.gg); // this one fails

    return {
        matchData: reduxStore.matchReducer.match
    }
}

/**
 * Exposes the necessary actions actions to this component.
 * 
 * @param { function } dispatch This function executes the called actions.
 */
const mapDispatchToProps = (dispatch) => {
    return {
        actions: bindActionCreators(matchActions, dispatch)
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(Match);

当我尝试console.log(reduxStore.matchReducer.match.all_word_counts)时,一切正常并且对象被打印出来。

见此截图

See this screenshot

正如您所知,有一个名为gg的属性。当我尝试打印时,我收到一条错误消息,指出all_word_counts未定义。

见此截图

See this screenshot

谁能告诉我我做错了什么?任何帮助表示赞赏!

0 个答案:

没有答案