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

 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
                                }
                        }

                总结:     这两种在需求上使用没有什么区别

猜你喜欢

转载自blog.51cto.com/14582569/2545909