-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-ssr.js
37 lines (32 loc) · 1022 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
35
36
37
/* eslint-disable react/prop-types, 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;
const ReduxWrapper = require('./redux-provider-wrapper').default;
function replaceRenderer({
bodyComponent,
replaceBodyHTMLString,
setHeadComponents
}) {
// Get the context of the page to collect 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;
exports.wrapRootElement = ReduxWrapper;