render() {
console.warn((this.name || this.displayName) + ' was rendered!');
return (<div>...</div>);
}
function withLog(WrappedComponent) {
return class extends React.Component {
displayName = WrappedComponent.displayName || WrappedComponent.name;
componentDidMount() {
console.log(`[${this.displayName}]: componentDidMount`);
}
...
render() {
console.log(`[${this.displayName}]: render`);
return <WrappedComponent {...this.props} />;
}
}
}
class MyComp extends React.Component {
...
}
const MyCompWithLog = withLog(MyComp);