-
Notifications
You must be signed in to change notification settings - Fork 833
/
_document.js
43 lines (38 loc) 路 1.19 KB
/
_document.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
/* eslint-disable react/no-danger, import/no-unresolved */
import React from 'react'
import Document, { Head, Main, NextScript } from 'next/document'
import { extractStyles } from 'evergreen-ui'
export default class MyDocument extends Document {
static getInitialProps({ renderPage }) {
const page = renderPage()
// `css` is a string with css from both glamor and ui-box.
// No need to get the glamor css manually if you are using it elsewhere in your app.
//
// `hydrationScript` is a script you should render on the server.
// It contains a stringified version of the glamor and ui-box caches.
// Evergreen will look for that script on the client and automatically hydrate
// both glamor and ui-box.
const { css, hydrationScript } = extractStyles()
return {
...page,
css,
hydrationScript
}
}
render() {
const { css, hydrationScript } = this.props
return (
<html>
<Head>
<title>SSR in Next.js</title>
<style dangerouslySetInnerHTML={{ __html: css }} />
</Head>
<body>
<Main />
{hydrationScript}
<NextScript />
</body>
</html>
)
}
}