高阶组件:
简单的说,高阶组件就是一个函数,这个函数接收一个组件作为输入,返回一个组件作为结果,因此,新返回的组件拥有了输入组件所不具备的功能。
import React from '.react';
function removeUserProp(WrappedComponent){
return class WrappingComponent extends React.Component{
render(){
const {user,...otherProps} = this.props;
return <WrappedComponent {...otherProps} />
}
}
}
export default removeUserProp;
该高阶函数的意思是:输入一个组件WrappedComponent,得到一个WrappindComponent组件,该组件没有user的属性。
const NewComponent = removeUserProps(SampleComponent) 可以使用上述的高阶函数。