April 2020
Intermediate to advanced
716 pages
18h 55m
English
To generate the CSS and markup representing the React frontend views on the server-side, we will use Material-UI's ServerStyleSheets and React's renderToString.
On every request received by the Express app, we will create a new ServerStyleSheets instance. Then, we will render the relevant React tree with the server-side collector in a call to renderToString, which ultimately returns the associated markup or HTML string version of the React view that is to be shown to the user in response to the requested URL.
The following code will be executed on every GET request that's received by the Express app.
mern-skeleton/server/express.js:
const sheets = new ServerStyleSheets()const context = {}const markup = ReactDOMServer.renderToString( ...Read now
Unlock full access