Skip to content

Latest commit

 

History

History
21 lines (18 loc) · 495 Bytes

04.HOC-props-proxy.md

File metadata and controls

21 lines (18 loc) · 495 Bytes

使用高阶组件做props代理.

Props代理

使用高阶组件能帮助我们对于传入的props进行修饰后传入真正的组件(类似于middleware的概念)

function HOC(WrappedComponent) {
  return class Test extends Component {
    render() {
      const newProps = {
        title: 'New Header',
        footer: false,
        showFeatureX: false,
        showFeatureY: true
      };

      return <WrappedComponent {...this.props} {...newProps} />
    }
  }
}