forked from freeCodeCamp/learn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-ssr.js
45 lines (40 loc) · 1.13 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
36
37
38
39
40
41
42
43
44
45
import React from 'react';
import { Provider } from 'react-redux';
import { renderToString } from 'react-dom/server';
import headComponents from './src/head';
import { createStore } from './src/redux/store';
exports.replaceRenderer = ({
history,
bodyComponent,
replaceBodyHTMLString
}) => {
const store = createStore(history);
const ConnectedBody = () => (
<Provider store={store}>{bodyComponent}</Provider>
);
replaceBodyHTMLString(renderToString(<ConnectedBody />));
};
exports.onRenderBody = ({ setHeadComponents, setPostBodyComponents }) => {
setHeadComponents([...headComponents]);
setPostBodyComponents([
<script
async='true'
key='chai-CDN'
src='https://cdnjs.cloudflare.com/ajax/libs/chai/4.1.2/chai.min.js'
/>,
<script
async={true}
src='https://www.googletagmanager.com/gtag/js?id=AW-795617839'
/>,
<script
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-795617839');
`
}}
/>
]);
};