-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-ssr.js
50 lines (45 loc) · 1.44 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
47
48
49
50
/* eslint-disable react/no-danger */
/* eslint-disable react/jsx-filename-extension */
import React from 'react'
import { renderToString } from 'react-dom/server'
import JssProvider from 'react-jss/lib/JssProvider'
import DateFnsUtils from '@date-io/date-fns'
import { MuiPickersUtilsProvider } from 'material-ui-pickers'
import { ApolloProvider } from 'react-apollo'
import getPageContext from './src/getPageContext'
import { client } from './src/utils/apolloClient'
// Mayerial-ui code to replace jss classes
function replaceRenderer({
bodyComponent,
replaceBodyHTMLString,
setHeadComponents,
}) {
// Get the context of the page to collected side effects.
const muiPageContext = getPageContext()
const bodyHTML = renderToString(
<JssProvider registry={muiPageContext.sheetsRegistry}>
{bodyComponent}
</JssProvider>
)
replaceBodyHTMLString(bodyHTML)
setHeadComponents([
<style
type="text/css"
id="jss-server-side"
key="jss-server-side"
dangerouslySetInnerHTML={{
__html: muiPageContext.sheetsRegistry.toString(),
}}
/>,
])
}
export default replaceRenderer
// Wrap the main component with the provedier from Apollo to query the graphql endpoint
// Add provider for the Date Picker
export const wrapRootElement = ({ element }) => (
<ApolloProvider client={client}>
<MuiPickersUtilsProvider utils={DateFnsUtils}>
{element}
</MuiPickersUtilsProvider>
</ApolloProvider>
)