Fork me on GitHub

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();
        }
    }
}

 

posted @ 2018-11-06 14:13  思考的大腿  阅读(145)  评论(0编辑  收藏  举报