【问题标题】:How do I use the compose function (of redux/ramda/recompose/etc)?如何使用 compose 功能(redux/ramda/recompose/etc)?
【发布时间】:2018-06-29 18:46:30
【问题描述】:

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

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

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

【问题讨论】:

    标签: reactjs functional-programming redux ramda.js recompose


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2019-02-09
      • 2017-05-14
      • 2018-11-30
      • 2019-02-10
      • 1970-01-01
      • 2018-03-16
      • 2017-12-31
      • 2018-10-13
      • 2019-05-24
      相关资源
      最近更新 更多