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
1b893518
Commit
1b893518
authored
May 07, 2017
by
Grokling
Committed by
Tim Neutkens
May 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SSR to examples/with-styled-components + bump styled_components v2 (#1908)
parent
12f423fa
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
11 deletions
+20
-11
.babelrc
examples/with-styled-components/.babelrc
+9
-0
package.json
examples/with-styled-components/package.json
+3
-1
_document.js
examples/with-styled-components/pages/_document.js
+8
-10
No files found.
examples/with-styled-components/.babelrc
0 → 100644
View file @
1b893518
{
"presets": [
"next/babel",
"stage-0"
],
"plugins": [
["styled-components", { "ssr": true, "displayName": true, "preprocess": false } ]
]
}
\ No newline at end of file
examples/with-styled-components/package.json
View file @
1b893518
...
@@ -7,10 +7,12 @@
...
@@ -7,10 +7,12 @@
"start"
:
"next start"
"start"
:
"next start"
},
},
"dependencies"
:
{
"dependencies"
:
{
"babel-plugin-styled-components"
:
"^1.1.4"
,
"babel-preset-stage-0"
:
"^6.24.1"
,
"next"
:
"latest"
,
"next"
:
"latest"
,
"react"
:
"^15.4.2"
,
"react"
:
"^15.4.2"
,
"react-dom"
:
"^15.4.2"
,
"react-dom"
:
"^15.4.2"
,
"styled-components"
:
"^
1.4.4
"
"styled-components"
:
"^
2.0.0-17
"
},
},
"author"
:
""
,
"author"
:
""
,
"license"
:
"ISC"
"license"
:
"ISC"
...
...
examples/with-styled-components/pages/_document.js
View file @
1b893518
import
Document
,
{
Head
,
Main
,
NextScript
}
from
'next/document'
import
Document
,
{
Head
,
Main
,
NextScript
}
from
'next/document'
import
styleSheet
from
'styled-components/lib/models/StyleSheet
'
import
{
ServerStyleSheet
}
from
'styled-components
'
export
default
class
MyDocument
extends
Document
{
export
default
class
MyDocument
extends
Document
{
static
async
getInitialProps
({
renderPage
})
{
const
page
=
renderPage
()
const
styles
=
(
<
style
dangerouslySetInnerHTML
=
{{
__html
:
styleSheet
.
rules
().
map
(
rule
=>
rule
.
cssText
).
join
(
'
\
n'
)
}}
/
>
)
return
{
...
page
,
styles
}
}
render
()
{
render
()
{
const
sheet
=
new
ServerStyleSheet
()
const
main
=
sheet
.
collectStyles
(
<
Main
/>
)
const
styleTags
=
sheet
.
getStyleElement
()
return
(
return
(
<
html
>
<
html
>
<
Head
>
<
Head
>
<
title
>
My
page
<
/title
>
<
title
>
My
page
<
/title
>
{
styleTags
}
<
/Head
>
<
/Head
>
<
body
>
<
body
>
<
Main
/>
<
div
className
=
'root'
>
{
main
}
<
/div
>
<
NextScript
/>
<
NextScript
/>
<
/body
>
<
/body
>
<
/html
>
<
/html
>
...
...
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