gpt4 book ai didi

reactjs - 如何将多个 actionCreators 包装到一个 props 中?

转载 作者:行者123 更新时间:2023-12-02 00:15:06 24 4
gpt4 key购买 nike

我收到以下错误:

未捕获的类型错误:this.props.dispatch不是函数

这是我的组件:

import React from 'react';
import PropTypes from 'prop-types';
import {Link} from 'react-router-dom';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import * as jobTitleSkillsActions from '../../actions/jobTitleSkillsActions';
import SkillList from './SkillList';
import * as userPositionActions from '../../actions/userPositionActions';

class SkillPage extends React.Component {

componentDidMount() {
this.props.dispatch(userPositionActions.loadUserPositions());
var job_title_id = this.props.user_positions[0].job_title_id; this.props.dispatch(jobTitleSkillsActions.loadJobTitleSkills(job_title_id));
}

.....

const mapStateToProps = state => {
return {
job_title_skills: state.job_title_skills,
user_positions: state.user_positions
};
};

function mapDispatchToProps(dispatch) {
return {
actions: {
userPositionActions: bindActionCreators(userPositionActions, dispatch),
jobTitleSkillsActions: bindActionCreators(jobTitleSkillsActions, dispatch),
}
};
}

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

我在这里做错了什么?

最佳答案

根据我的评论,这将是绑定(bind)多个子对象的 Action 创建者的正确语法:

function mapDispatchToProps(dispatch) {
return {
userPositionActions : bindActionCreators(userPositionActions, dispatch),
jobTitleSkillsActions: bindActionCreators(jobTitleSkillsActions, dispatch),
}
}

关于reactjs - 如何将多个 actionCreators 包装到一个 props 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44403700/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com