高阶组件
import React, { Component } from 'react';
import './LoadingHOC.css';
const isEmpty = (prop) => (
prop === null ||
prop === undefined ||
(prop.hasOwnProperty('length') && prop.length === 0) ||
(prop.constructor === Object && Object.keys(prop).length === 0)
);
const withLoadingHOC = (loadingProp) => (WrappedComponent) => {
return class extends Component {
render() {
return isEmpty(this.props[loadingProp]) ? <div className="loader" /> : <WrappedComponent {...this.props} />;
}
}
}render prop是什么
Function as Child Component
最后更新于