-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-ssr.js
35 lines (32 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
35
import React from 'react';
import { renderToString } from 'react-dom/server';
import { Provider } from 'react-redux';
import { JssProvider } from 'react-jss';
import getPageContext from './src/getPageContext';
import { configureStore } from './store';
exports.replaceRenderer = ({ bodyComponent, replaceBodyHTMLString, setHeadComponents }) => {
// Get the context of the page to collected side effects.
const pageContext = getPageContext();
const store = configureStore();
const bodyHTML = renderToString(
<Provider store={store}>
<JssProvider
registry={pageContext.sheetsRegistry}
generateClassName={pageContext.generateClassName}
>
{React.cloneElement(bodyComponent, {
pageContext,
})}
</JssProvider>
</Provider>
);
replaceBodyHTMLString(bodyHTML);
setHeadComponents([
<style
type="text/css"
id="server-side-jss"
key="server-side-jss"
dangerouslySetInnerHTML={{ __html: pageContext.sheetsRegistry.toString() }}
/>,
]);
};