I use response-fullstack as a scaffold to start my project.
I find that its sample code is very different from the official confirmation document.
Sample code is as follows:
@withStyles(styles)
class Header {
render() {
return (
);
}
}
function withStyles(styles) {
return (ComposedComponent) => class WithStyles {
static contextTypes = {
onInsertCss: PropTypes.func
};
constructor() {
this.refCount = 0;
ComposedComponent.prototype.renderCss = function (css) {
let style;
if (ExecutionEnvironment.canUseDOM) {
if (this.styleId && (style = document.getElementById(this.styleId))) {
if ('textContent' in style) {
style.textContent = css;
} else {
style.styleSheet.cssText = css;
}
} else {
this.styleId = `dynamic-css-${count++}`;
style = document.createElement('style');
style.setAttribute('id', this.styleId);
style.setAttribute('type', 'text/css');
if ('textContent' in style) {
style.textContent = css;
} else {
style.styleSheet.cssText = css;
}
document.getElementsByTagName('head')[0].appendChild(style);
this.refCount++;
}
} else {
this.context.onInsertCss(css);
}
}.bind(this);
}
componentWillMount() {
}
componentWillUnmount() {
}
render() {
return <ComposedComponent {...this.props} />;
}
};
}
It doesn't even expand React.Componentat all, I don’t see it use prototype inheritance.
But it works, and each component can be used as an official document.
Does this mean that if I implement a class using a method render, I implement a React component?
source
share