-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-ssr.js
46 lines (41 loc) · 1.14 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
46
import React from 'react';
import { JssProvider } from 'react-jss';
import { MuiThemeProvider } from '@material-ui/core/styles';
import { CssBaseline } from '@material-ui/core';
import getPageContext from './src/getPageContext';
const muiPageContext = getPageContext();
const sheetsRegistryMap = muiPageContext.sheetsManager;
export const wrapRootElement = ({ element }) => {
return (
<JssProvider
registry={muiPageContext.sheetsRegistry}
generateClassName={muiPageContext.generateClassName}
>
<MuiThemeProvider
theme={muiPageContext.theme}
sheetsManager={sheetsRegistryMap}
>
<CssBaseline />
{element}
</MuiThemeProvider>
</JssProvider>
);
};
export const onRenderBody = ({ setHeadComponents }) => {
setHeadComponents([
<link
key="font-lato-stylesheet"
href="https://fonts.googleapis.com/css?family=Lato:400,700"
rel="stylesheet"
/>,
// Material UI
<style
type="text/css"
id="server-side-jss"
key="server-side-jss"
dangerouslySetInnerHTML={{
__html: muiPageContext.sheetsRegistry.toString()
}}
/>
]);
};