脚本宝典收集整理的这篇文章主要介绍了react 高阶组件,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
高阶组件本质是函数,参数是 组件1 返回组件2,高阶组件是为了复用通用逻辑
高阶组件eg:
import React, { Component } From 'react';
const withPersistentData = data => WrappedComponent => {
return class extends Component {
constructor(props) {
super(props);
}
render() {
return (
<WrappedComponent data={data} />
)
}
}
}
export default withPersistentData
尝试用定义好的高阶组件
import React, { Component } from 'react';
import HighComponent from './HighComponent';
class LowComponent extends Component {
constructor(props) {
super(props);
}
render() {
return (
<div>{this.props.data}</div>
)
}
}
const MyComponent = HighComponent('Hello')(LowComponent)
export default MyComponent
以上是脚本宝典为你收集整理的react 高阶组件全部内容,希望文章能够帮你解决react 高阶组件所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。