React【 HOC & Render-Props 】

220 阅读1分钟

HOC

High-Order-Props高阶组件

A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API, per se. They are a pattern that emerges from React’s compositional nature.

Concretely, a higher-order component is a function that takes a component and returns a new component. reference

  • 具体而言,高阶组件就是一个方法,它接收一个组件,返回一个新的组件。

  • 实现代码复用

  • 类似于AOP面向切片模式:为原组件添加新功能

const EnhancedComponent = higherOrderComponent(WrappedComponent);

todo...