forked from joostdecock/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-ssr.js
More file actions
34 lines (30 loc) · 908 Bytes
/
gatsby-ssr.js
File metadata and controls
34 lines (30 loc) · 908 Bytes
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
import wrapWithProvider from "./src/store/wrapWithProvider";
import React from "react";
import { renderToString } from "react-dom/server";
import JssProvider from "react-jss/lib/JssProvider";
import getPageContext from "./src/getPageContext";
export const replaceRenderer = function({
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()
}}
/>
]);
};
export const wrapRootElement = wrapWithProvider;