-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathgatsby-ssr.js
More file actions
34 lines (29 loc) · 841 Bytes
/
gatsby-ssr.js
File metadata and controls
34 lines (29 loc) · 841 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
const React = require('react');
const Styletron = require('styletron-server');
const {StyletronProvider} = require('styletron-react');
const {renderToString} = require('react-dom/server');
exports.replaceRenderer = ({
bodyComponent,
setHeadComponents,
replaceBodyHTMLString,
}) => {
const styletron = new Styletron();
const app = (
<StyletronProvider styletron={styletron}>{bodyComponent}</StyletronProvider>
);
replaceBodyHTMLString(renderToString(app));
const stylesheets = styletron.getStylesheets();
const headComponents = stylesheets.map((sheet, index) => {
return (
<style
media={sheet.media}
className="_styletron_hydrate_"
key={index}
dangerouslySetInnerHTML={{
__html: sheet.css,
}}
/>
);
});
setHeadComponents(headComponents);
};