我得到的东西就像foo(bar(baz)))可以重写为compose(foo,bar,baz)。然而,现实生活中的例子呢? 例如,我可能有:
export default {
loadData,
component: connect(mapStateToProps, {
actionCreator1,
actionCreator2
})(requireAuth(showToggle({ChildComponent: aComponentOfMine, anotherField: `becauseStringsAreCool`})))
是否可以使用compose重构组件值?
答案 0 :(得分:2)
您的示例中的component
值可以重写为使用compose
,如下所示:
const buildComponent = compose(
connect(mapStateToProps, {
actionCreator1,
actionCreator2
}),
requireAuth,
showToggle
)
export default {
loadData,
component: buildComponent({
ChildComponent: aComponentOfMine,
anotherField: `becauseStringsAreCool`
})
}