Reputation: 83
I get that something like foo(bar(baz))) can be re-written as compose(foo, bar, baz). What about real-life examples, however? For instance, I may have:
export default {
loadData,
component: connect(mapStateToProps, {
actionCreator1,
actionCreator2
})(requireAuth(showToggle({ChildComponent: aComponentOfMine, anotherField: `becauseStringsAreCool`})))
Is it possible to refactor the component value using compose?
Upvotes: 0
Views: 424
Reputation: 6516
The component
value in your example could be rewritten to use compose
like so:
const buildComponent = compose(
connect(mapStateToProps, {
actionCreator1,
actionCreator2
}),
requireAuth,
showToggle
)
export default {
loadData,
component: buildComponent({
ChildComponent: aComponentOfMine,
anotherField: `becauseStringsAreCool`
})
}
Upvotes: 2