-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-ssr.js
34 lines (28 loc) · 1.02 KB
/
gatsby-ssr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/ssr-apis/
*/
// You can delete this file if you're not using it
/* eslint-disable react/no-danger */
const React = require('react');
const { renderToString } = require('react-dom/server');
const JssProvider = require('react-jss/lib/JssProvider').default;
const getPageContext = require('./src/getPageContext').default;
function replaceRenderer({ bodyComponent, replaceBodyHTMLString, setHeadComponents }) {
// Get the context of the page to collected side effects.
const muiPageContext = getPageContext();
const bodyHTML = renderToString(
<JssProvider registry={muiPageContext.sheetsRegistry}>{bodyComponent}</JssProvider>,
);
replaceBodyHTMLString(bodyHTML);
setHeadComponents([
<style
type="text/css"
id="jss-server-side"
key="jss-server-side"
dangerouslySetInnerHTML={{ __html: muiPageContext.sheetsRegistry.toString() }}
/>,
]);
}
exports.replaceRenderer = replaceRenderer;