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();
}
}
}
以上是 react 高阶组件 的全部内容, 来源链接: utcz.com/z/381255.html