rsnext/examples/with-emotion/pages/_document.js
Mitchell Hamilton 31db8dd932 Add with-emotion example (#2395)
* Add with-emotion example

* Fix linting errors
2017-06-29 07:44:48 +02:00

33 lines
775 B
JavaScript

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