Skip to content

Commit

Permalink
Render styled-jsx in _document example (#1287)
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens authored and arunoda committed Feb 27, 2017
1 parent 1971517 commit e1babdf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/with-cxs/pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cxs from 'cxs'
export default class MyDocument extends Document {
static async getInitialProps ({ renderPage }) {
const page = renderPage()
let style = cxs.getCss()
const style = cxs.getCss()
return { ...page, style }
}

Expand Down
5 changes: 2 additions & 3 deletions examples/with-styled-components/pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import styleSheet from 'styled-components/lib/models/StyleSheet'
export default class MyDocument extends Document {
static async getInitialProps ({ renderPage }) {
const page = renderPage()
const style = styleSheet.rules().map(rule => rule.cssText).join('\n')
return { ...page, style }
const styles = styleSheet.rules().map(rule => rule.cssText).join('\n')
return { ...page, styles }

This comment has been minimized.

Copy link
@aesopwolf

aesopwolf Mar 17, 2017

Just curious, what's the point of returning ...page here? It doesn't look like it's being used anywhere in the render function.

}

render () {
return (
<html>
<Head>
<title>My page</title>
<style dangerouslySetInnerHTML={{ __html: this.props.style }} />
</Head>
<body>
<Main />
Expand Down
8 changes: 5 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,13 @@ Pages in `Next.js` skip the definition of the surrounding document's markup. For
```jsx
// ./pages/_document.js
import Document, { Head, Main, NextScript } from 'next/document'
import flush from 'styled-jsx/server'

export default class MyDocument extends Document {
static async getInitialProps (ctx) {
const props = await Document.getInitialProps(ctx)
return { ...props, customValue: 'hi there!' }
static getInitialProps ({ renderPage }) {
const {html, head} = renderPage()
const styles = flush()
return { html, head, styles }
}

render () {
Expand Down

0 comments on commit e1babdf

Please sign in to comment.