【发布时间】:2018-03-05 06:20:05
【问题描述】:
我正在为我的项目使用react-redux 和redux-thunk。
我必须使用connect 将我的actions 注入到组件中。
connect([mapStateToProps], [mapDispatchToProps], [mergeProps], [options])
我的任务是上一级。我不想只以这种形式注入多个操作:
{
doThis(),
doThat()
}
但是以这种形式:
{
this: {
doThis1(),
doThis2()
}
that: {
doThat()
}
}
所以基本上我的问题是我想调度多个动作创建器文件,因为我希望它们像这样组织。
我尝试了这个版本,它显然不起作用,因为调度没有注入每个 Thunk Action Creator:
import * as actions from './actions'
const mapDispatchToProps = (dispatch) => {
return {
dataActions: {
...actions.dataActions
}
};
}
export default connect(null, mapDispatchToProps)(Component);
所以我的最后一个问题是:
我什至应该以这种方式使用 Redux 吗?我可以这样组织我的文件吗?如果可以,如何?
【问题讨论】:
标签: redux react-redux redux-thunk