reactjs - 无法将调度连接到道具
问题描述
我有一个类组件,我想连接到商店以提取数据。
我已经使用功能组件测试了该操作,并且运行良好。由于一些限制,我决定使用类组件。
问题是“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)
我不确定我做错了什么,但那里缺少一些东西,我找不到根本原因。
知道有什么问题吗?
谢谢
解决方案
您的默认导出应该是连接的组件,而不是未连接的组件。
export default connect(mapStateToProps, mapDispatchToProps)(TchExportButton);
(确保删除顶部的导出默认值)
推荐阅读
- amazon-web-services - AWS System Manager 可以以 ec2-user 身份登录吗
- javascript - 使用 vuetify 验证密码
- vim - Vim 插件不在主目录中时不起作用
- sql - oracle替换逗号,但前提是后面没有空格
- nginx - 调用 nginx 提供的 PHP 页面而不使用文件扩展名
- azure-devops - Azure 管道通用包任务失败并出现错误“提供的包名称无效”
- javascript - 如果输入值是 = 某些定义的代码,则删除 ID
- c# - 在 ASP.NET 中正确使用 Task.Run 和 Task.WaitAll 进行 EF 调用
- sql - 如何用最近的记录替换缺失的数字求和
- wcf - F# 客户端、IIS7 和 WCF