react 高阶组件

属性代理

import React, { Component } from 'react'
export default function (WrappedComponent) {
    return class hocHistory extends Component {
        componentDidMount() {
            console.log(this.state);
        }
        render() {
            const newProps = {
                test:'新属性'
              }
            return <WrappedComponent {...this.props} {...newProps}/>
        }
    }
}

反向继承

export default function (WrappedComponent) {
    return class hocHistory extends WrappedComponent {
        render() {
            return super.render();
        }
    }
}
原文地址:https://www.cnblogs.com/thinkingthigh/p/9914987.html