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(); } } }
用心写代码,不辜负程序员之名。