2017-01-23 23:29:15 +00:00
|
|
|
import Document, { Head, Main, NextScript } from 'next/document'
|
2017-06-13 20:50:42 +00:00
|
|
|
import { renderToSheetList } from 'fela-dom'
|
|
|
|
import getRenderer from '../fela'
|
2017-01-23 23:29:15 +00:00
|
|
|
|
|
|
|
export default class MyDocument extends Document {
|
|
|
|
static getInitialProps ({ renderPage }) {
|
|
|
|
const page = renderPage()
|
|
|
|
const renderer = getRenderer()
|
|
|
|
|
2017-06-13 20:50:42 +00:00
|
|
|
const sheetList = renderToSheetList(renderer)
|
2017-01-23 23:29:15 +00:00
|
|
|
renderer.clear()
|
|
|
|
|
|
|
|
return {
|
|
|
|
...page,
|
2017-06-13 20:50:42 +00:00
|
|
|
sheetList
|
2017-01-23 23:29:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2017-06-13 20:50:42 +00:00
|
|
|
const styleNodes = this.props.sheetList.map(({ type, media, css }) => (
|
|
|
|
<style data-fela-type={type} media={media}>{css}</style>
|
|
|
|
))
|
|
|
|
|
2017-01-23 23:29:15 +00:00
|
|
|
return (
|
|
|
|
<html>
|
|
|
|
<Head>
|
|
|
|
<title>My page</title>
|
2017-06-13 20:50:42 +00:00
|
|
|
{styleNodes}
|
2017-01-23 23:29:15 +00:00
|
|
|
</Head>
|
|
|
|
<body>
|
|
|
|
<Main />
|
|
|
|
<NextScript />
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|