0

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?

chachathok
  • 83
  • 1
  • 6

1 Answers1

2

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`
  })
}
Scott Christopher
  • 6,458
  • 23
  • 26