1、React高阶组件
function logHoc(WrappedComponent) {
return class extends React.Component {
constructor(props) {
super(props);
}
componentWillMount() {
this.start = Date.now();
}
componentDidMount() {
this.end = Date.now();
console.log(`渲染时间:${this.end - this.start} ms`);
}
componentWillUnmount() {}
render() {
console.log(this.props);
return (
<div>
<div className="title">{this.props.loading ? 1 : 2}</div>
<WrappedComponent {...this.props} />
</div>
);
}
};
}
export default React.memo(logHoc(TopSearch));
网友评论