【问题标题】:React recompose pass propsReact recompose pass 道具
【发布时间】:2017-08-09 02:08:53
【问题描述】:

例如,我们有一个容器<ContainerName data=someData> 并传递一些道具数据

在这个容器中,我们使用 recompose 并有以下代码:

const enhance = compose(
      withProps({
        statuses: ['ordered', 'received'],
      }),
      withProps(
        // how do I pass props from this container to component ?
      ),
      withState('error', 'setError', false),
      withState('successAdded', 'setSuccessAdded', false),
      withState('loading', 'setLoading', false),
      withState('confirmModal', 'setConfirmModal', false),
...
export default enhance(ComponentForm);

我们如何将属于这个容器的 props 传递给我们的组件?

【问题讨论】:

    标签: reactjs recompose


    【解决方案1】:

    组件不需要声明它将通过 recompose HOCs 接收到的所有 props 才能使用它(除非您通过 mapProps 在 compose 函数中明确省略了 props)。

    像使用普通组件一样传递数据,并让您的子组件像使用任何普通道具一样使用它

    【讨论】:

      猜你喜欢
      • 2018-10-28
      • 2018-02-05
      • 2018-12-16
      • 2019-02-21
      • 2018-05-21
      • 2017-10-24
      • 2019-03-05
      • 2019-02-04
      • 2019-01-07
      相关资源
      最近更新 更多