1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-emotion/pages/_document.js
Matija Marohnić 3c92524b06 Update example with emotion (#2837)
* Update example with emotion

Emotion is now split into separate packages using Lerna.

* Update Next.js in emotion example
2017-08-24 08:27:49 +02:00

38 lines
854 B
JavaScript

import Document, { Head, Main, NextScript } from 'next/document'
import { extractCritical } from 'emotion-server'
import { flush } from 'emotion'
const dev = process.env.NODE_ENV !== 'production'
export default class MyDocument extends Document {
static getInitialProps ({ renderPage }) {
if (dev) { flush() }
const page = renderPage()
const styles = extractCritical(page.html)
return { ...page, ...styles }
}
constructor (props) {
super(props)
const { __NEXT_DATA__, ids } = props
if (ids) {
__NEXT_DATA__.ids = ids
}
}
render () {
return (
<html>
<Head>
<title>With Emotion</title>
<style dangerouslySetInnerHTML={{ __html: this.props.css }} />
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
)
}
}