-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-ssr.js
34 lines (30 loc) · 960 Bytes
/
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
// See https://github.com/mui-org/material-ui/tree/master/examples/gatsby
const React = require("react"),
{ renderToString } = require("react-dom/server"),
StylesProvider = require("@material-ui/styles/StylesProvider").default,
getPageContext = require("./src/utils/getPageContext").default;
function replaceRenderer({
bodyComponent,
replaceBodyHTMLString,
setHeadComponents,
}) {
// Get the context of the page to collected side effects.
const muiPageContext = getPageContext(),
bodyHTML = renderToString(
<StylesProvider sheetsRegistry={muiPageContext.sheetsRegistry}>
{bodyComponent}
</StylesProvider>
);
replaceBodyHTMLString(bodyHTML);
setHeadComponents([
<style
type="text/css"
id="jss-server-side"
key="jss-server-side"
dangerouslySetInnerHTML={{
__html: muiPageContext.sheetsRegistry.toString(),
}}
/>,
]);
}
exports.replaceRenderer = replaceRenderer;