Commit 3910b6de authored by Yuki Takemoto's avatar Yuki Takemoto Committed by Joe Haddad

Upgrade next of with-typescript-styled-components sample (#7788)

parent 7da546a3
{ {
"presets": ["next/babel", "@zeit/next-typescript/babel"], "presets": ["next/babel"],
"plugins": [["styled-components", { "ssr": true }]] "plugins": [["styled-components", { "ssr": true }]]
} }
/// <reference types="next" />
/// <reference types="next/types/global" />
const withTypescript = require('@zeit/next-typescript')
module.exports = withTypescript()
...@@ -7,17 +7,18 @@ ...@@ -7,17 +7,18 @@
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"@types/next": "^8.0.1", "next": "9.0.0",
"@types/react": "^16.8.6", "react": "16.8.6",
"@types/styled-components": "^4.1.11", "react-dom": "16.8.6",
"@zeit/next-typescript": "^1.1.1",
"next": "^8.0.3",
"react": "^16.8.3",
"react-dom": "^16.8.3",
"styled-components": "^4.1.3" "styled-components": "^4.1.3"
}, },
"devDependencies": { "devDependencies": {
"babel-plugin-styled-components": "^1.10.0" "@types/node": "12.0.12",
"@types/react": "16.8.23",
"@types/react-dom": "16.8.4",
"@types/styled-components": "4.1.16",
"babel-plugin-styled-components": "^1.10.0",
"typescript": "3.5.2"
}, },
"license": "ISC" "license": "ISC"
} }
\ No newline at end of file
import Document, { NextDocumentContext } from 'next/document' import Document, { DocumentContext } from 'next/document'
import { ServerStyleSheet } from 'styled-components' import { ServerStyleSheet } from 'styled-components'
export default class MyDocument extends Document { export default class MyDocument extends Document {
static async getInitialProps(ctx: NextDocumentContext) { static async getInitialProps(ctx: DocumentContext) {
const sheet = new ServerStyleSheet() const sheet = new ServerStyleSheet()
const originalRenderPage = ctx.renderPage const originalRenderPage = ctx.renderPage
...@@ -15,12 +15,12 @@ export default class MyDocument extends Document { ...@@ -15,12 +15,12 @@ export default class MyDocument extends Document {
const initialProps = await Document.getInitialProps(ctx) const initialProps = await Document.getInitialProps(ctx)
return { return {
...initialProps, ...initialProps,
styles: ( styles: [
<> <>
{initialProps.styles} {initialProps.styles}
{sheet.getStyleElement()} {sheet.getStyleElement()}
</> </>,
), ],
} }
} finally { } finally {
sheet.seal() sheet.seal()
......
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
"target": "esnext", "target": "esnext",
"module": "esnext", "module": "esnext",
"jsx": "preserve", "jsx": "preserve",
"lib": ["dom", "es2017"], "lib": [
"dom",
"es2017"
],
"moduleResolution": "node", "moduleResolution": "node",
"allowJs": true, "allowJs": true,
"noEmit": true, "noEmit": true,
...@@ -15,6 +18,17 @@ ...@@ -15,6 +18,17 @@
"removeComments": false, "removeComments": false,
"preserveConstEnums": true, "preserveConstEnums": true,
"sourceMap": true, "sourceMap": true,
"esModuleInterop": true "esModuleInterop": true,
} "forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"isolatedModules": true
},
"exclude": [
"node_modules"
],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
]
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment