开发者社区> 问答> 正文

#React 如何为HOC组件创建道具代理?

#React 如何为HOC组件创建道具代理?

展开
收起
因为相信,所以看见。 2020-05-07 17:01:25 919 0
1 条回答
写回答
取消 提交回答
  • 阿里,我所有的向往

    您可以使用props代理模式添加/编辑传递给组件的props,如下所示:

    function HOC(WrappedComponent) {
      return class Test extends Component {
        render() {
          const newProps = {
            title: 'New Header',
            footer: false,
            showFeatureX: false,
            showFeatureY: true
          }
    
          return <WrappedComponent {...this.props} {...newProps} />
        }
      }
    }
    
    2020-05-07 17:02:22
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
利用编译将 Vue 组件转成 React 组件 立即下载
React Native 全量化实践 立即下载
React在大型后台管理项目中的工程实践 立即下载