首页 > 解决方案 > 无法将调度连接到道具

问题描述

我有一个类组件,我想连接到商店以提取数据。

我已经使用功能组件测试了该操作,并且运行良好。由于一些限制,我决定使用类组件。

问题是“getTableDataAction”不存在,尽管我确实通过连接函数连接了调度。

结果我会得到一个愚蠢的错误:“ TypeError: this.props.getTableDataAction is not a function

 export default class TchExportButton extends Component {

constructor(props) {
    super(props);
    this.state = {
        selectedIndex: 0,
        anchorEl: null,
        options: ['Select drill down report',
            'Destroyed DCA',
            'Repaired - A008']
    }
}

componentDidUpdate(prevState) {
    if (this.state.selectedIndex !== prevState.selectedIndex) {
        if (this.state.selectedIndex > 0) {
            this.props.getTableDataAction(this.state.selectedIndex)
        }
    }
}
.....
...
..

const mapStateToProps = (state) => {
return {
    data: state.tchCommecialTableData.data,
    }
 }


const mapDispatchToProps = (dispatch) => {
     return {
    getTableDataAction: (buttonId) => dispatch(engineeringDataAction.getTableDataAction(buttonId))
   }
}

 connect(mapStateToProps, mapDispatchToProps)

我不确定我做错了什么,但那里缺少一些东西,我找不到根本原因。

知道有什么问题吗?

谢谢

标签: reactjsreduxreact-redux

解决方案


您的默认导出应该是连接的组件,而不是未连接的组件。

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

(确保删除顶部的导出默认值)


推荐阅读