Skip to content

Commit

Permalink
Convert with-goober example to TS (#39761)
Browse files Browse the repository at this point in the history
## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc]


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
  • Loading branch information
kasperaamodt and ijjk committed Aug 21, 2022
1 parent 74fb7ba commit bc4d98a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
13 changes: 9 additions & 4 deletions examples/with-goober/package.json
Expand Up @@ -6,10 +6,15 @@
"start": "next start"
},
"dependencies": {
"goober": "^2.0.2",
"goober-autoprefixer": "^1.2.0",
"goober": "^2.1.10",
"goober-autoprefixer": "^1.2.3",
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^18.7.7",
"@types/react": "^18.0.17",
"typescript": "^4.7.4"
}
}
@@ -1,12 +1,13 @@
import React from 'react'
import { prefix } from 'goober-autoprefixer'
import { createElement } from 'react'
import { setup } from 'goober'
import { prefix } from 'goober/prefixer'
import type { AppProps } from 'next/app'

// goober's needs to know how to render the `styled` nodes.
// So to let it know, we run the `setup` function with the
// `createElement` function and prefixer function.
setup(React.createElement, prefix)
setup(createElement, prefix)

export default function App({ Component, pageProps }) {
export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
@@ -1,10 +1,19 @@
import Document, { Html, Head, Main, NextScript } from 'next/document'
import { extractCss } from 'goober'
import NextDocument, {
DocumentContext,
Head,
Html,
Main,
NextScript,
} from 'next/document'

export default class MyDocument extends Document {
static async getInitialProps({ renderPage }) {
type Props = {
css: string
}

class Document extends NextDocument<Props> {
static async getInitialProps({ renderPage }: DocumentContext) {
const page = await renderPage()
// Extrach the css for each page render
const css = extractCss()
return { ...page, css }
}
Expand All @@ -27,3 +36,5 @@ export default class MyDocument extends Document {
)
}
}

export default Document
File renamed without changes.
20 changes: 20 additions & 0 deletions examples/with-goober/tsconfig.json
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}

0 comments on commit bc4d98a

Please sign in to comment.