React 实现使用高阶组件两种方式

爱⌒轻易说出口 提交于 2020-11-03 16:01:39
 React 使用高阶组件有两种 一种是 调用 传入的组件 另外 一种是 继承传入的组件。高阶组件 就是一个函数 接受参数组件 返回的也是组件

            1、function Htight1( componentName ){
                         return class WrapComponent extends Components {
                                  render(){
                                             return (
                                                    <componentName  ...this.props>
                                                           { this.props.children }
                                                        </componentName>
                                                 )
                                        }
                             }
                    }

                    const demo1  = class extends Components {

                    }

                    第二种 继承传入组件

                        function  Htight1(componentName){
                            return  class WrapComponents{
                                   //doSomething
                                }
                        }

                总结:     这两种在需求上使用没有什么区别
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!