Which one of these two syntaxes do you prefer for pre-rendering critical CSS in ReactJS apps?
import styles from './MyComponent.less';
import { withStyles } from '../decorators';
@withStyles(styles)
class MyComponent {
render() {
return (
<div className={this.className()}>
<div className={this.className('foo')}>Hello</div>
</div>
);
}
}
export default MyComponent;
import { withStyles } from '../decorators';
@withStyles
class MyComponent {
static styles = require('./MyComponent.less');
render() {
return (
<div className={this.className()}>
<div className={this.className('foo')}>Hello</div>
</div>
);
}
}
export default MyComponent;
import { withStyles } from '../decorators';
@withStyles
class MyComponent {
static displayName = 'MyComponent';
render() {
return (
<div className={this.className()}>
<div className={this.className('foo')}>Hello</div>
</div>
);
}
}
export default MyComponent;
// MyComponent.less
.MyComponent {
border: 1px solid red;
&-foo {
color: green;
}
}
server.get('*', (req, res) => {
let title;
let css = [];
let html = React.renderToString(<App
onSetTitle={val => title = val; }
onInsertCss={val => css.push(val); } />);
res.send(`
<html>
<head>
<title>${title}</title>
<style>${css.join('')}</style>
<head>
<body>
<div id="app">${html}</div>
<script src="/app.js"></script>
</body>
</body>`);
});