I want to create a react app with both client side and server side rendering.
Here is the example:
import styles from './Main.css';
import React, {Component} from 'react';
import Info from './Info/Info';
import Record from './Record/Record'
export default class Main extends Component {
render() {
return (
<div className={styles.main}>
<div className={styles.mainIn + ' clearfix'}>
<div className={styles.mainLeft}>
<Info info_num="2012201972"/>
</div>
<div className={styles.mainRight}>
<div className="clearfix mb20">
<Record />
</div>
</div>
</div>
</div>
)
}
}
In this component Main
, it needs to be rendered at the client side except <Record />
Component Record
import styles from './Record.css';
import layout from '../../shared/styles/layout.css'
import React, {Component} from 'react';
export default class Record extends Component {
render() {
return (
<div className="float_two">
<div className={layout.box + ' mr10'}>
This is Record!
</div>
<div>
)
}
}
Here is my question:
I have searched some examples of server-side rendering examples with ReactDom.renderToString
and react-router
. However, there is no tutorial with both client-side and server-side rendering.
What I want to achieve is that, client first loads and renders Component <Main />
and then loads <Record />
from server-side.
Another question is that, how to load the style module Record.css with renderToString, because I think in this renderToString can just load the html things not the css.