Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
e1babdfe
Commit
e1babdfe
authored
Feb 27, 2017
by
Tim Neutkens
Committed by
Arunoda Susiripala
Feb 27, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Render styled-jsx in _document example (#1287)
parent
1971517c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
7 deletions
+8
-7
_document.js
examples/with-cxs/pages/_document.js
+1
-1
_document.js
examples/with-styled-components/pages/_document.js
+2
-3
readme.md
readme.md
+5
-3
No files found.
examples/with-cxs/pages/_document.js
View file @
e1babdfe
...
...
@@ -4,7 +4,7 @@ import cxs from 'cxs'
export
default
class
MyDocument
extends
Document
{
static
async
getInitialProps
({
renderPage
})
{
const
page
=
renderPage
()
le
t
style
=
cxs
.
getCss
()
cons
t
style
=
cxs
.
getCss
()
return
{
...
page
,
style
}
}
...
...
examples/with-styled-components/pages/_document.js
View file @
e1babdfe
...
...
@@ -4,8 +4,8 @@ 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
style
s
=
styleSheet
.
rules
().
map
(
rule
=>
rule
.
cssText
).
join
(
'
\
n'
)
return
{
...
page
,
style
s
}
}
render
()
{
...
...
@@ -13,7 +13,6 @@ export default class MyDocument extends Document {
<
html
>
<
Head
>
<
title
>
My
page
<
/title
>
<
style
dangerouslySetInnerHTML
=
{{
__html
:
this
.
props
.
style
}}
/
>
<
/Head
>
<
body
>
<
Main
/>
...
...
readme.md
View file @
e1babdfe
...
...
@@ -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
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment