forked from bdougie/codeNaija
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-ssr.js
24 lines (21 loc) · 839 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
import React from "react";
import { renderToString } from "react-dom/server";
import { ServerStyleSheet } from "styled-components";
import AppProvider from "store/provider";
import wrapPageElementWithTransition from "helpers/wrapPageElement";
export const replaceRenderer = ({
bodyComponent,
replaceBodyHTMLString,
setHeadComponents
}) => {
// React Context in SSR/build
const ConnectedBody = () => <AppProvider>{bodyComponent}</AppProvider>;
replaceBodyHTMLString(renderToString(<ConnectedBody />));
// Add styled-components in SSR/build
const sheet = new ServerStyleSheet();
const bodyHTML = renderToString(sheet.collectStyles(<ConnectedBody />));
const styleElement = sheet.getStyleElement();
setHeadComponents(styleElement);
};
// Page Transitions
export const wrapPageElement = wrapPageElementWithTransition;