如何使用(redux/ramda/recompose/etc)的撰写功能?

How do I use the compose function (of redux/ramda/recompose/etc)?

我知道 foo(bar(baz))) 可以重写为 compose(foo, bar, baz)。然而,现实生活中的例子呢? 例如,我可能有:

export default {
loadData,
component: connect(mapStateToProps, {
    actionCreator1,
    actionCreator2
})(requireAuth(showToggle({ChildComponent: aComponentOfMine, anotherField: `becauseStringsAreCool`})))

是否可以使用 compose 重构组件值?

您示例中的 component 值可以重写为使用 compose,如下所示:

const buildComponent = compose(
  connect(mapStateToProps, {
    actionCreator1,
    actionCreator2
  }),
  requireAuth,
  showToggle
)

export default {
  loadData,
  component: buildComponent({
    ChildComponent: aComponentOfMine,
    anotherField: `becauseStringsAreCool`
  })
}