Unverified Commit aa5be3ff authored by Henrik Wenz's avatar Henrik Wenz Committed by GitHub

[Docs] Migrate with-react-jss to typescript (#40308)

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent 62c7eff3
{
"presets": ["next/babel"]
}
...@@ -7,8 +7,13 @@ ...@@ -7,8 +7,13 @@
}, },
"dependencies": { "dependencies": {
"next": "latest", "next": "latest",
"react": "^17.0.2", "react": "^18.2.0",
"react-dom": "^17.0.2", "react-dom": "^18.2.0",
"react-jss": "^10.3.0" "react-jss": "^10.9.2"
},
"devDependencies": {
"@types/node": "18.7.15",
"@types/react": "18.0.18",
"typescript": "4.8.2"
} }
} }
import type { AppProps } from 'next/app'
import { useEffect } from 'react' import { useEffect } from 'react'
export default function App({ Component, pageProps }) { export default function App({ Component, pageProps }: AppProps) {
useEffect(() => { useEffect(() => {
const style = document.getElementById('server-side-styles') const style = document.getElementById('server-side-styles')
if (style) { if (style && style.parentNode) {
style.parentNode.removeChild(style) style.parentNode.removeChild(style)
} }
}, []) }, [])
......
import Document from 'next/document' import Document, { DocumentContext } from 'next/document'
import { SheetsRegistry, JssProvider, createGenerateId } from 'react-jss' import { SheetsRegistry, JssProvider, createGenerateId } from 'react-jss'
export default class JssDocument extends Document { export default class JssDocument extends Document {
static async getInitialProps(ctx) { static async getInitialProps(ctx: DocumentContext) {
const registry = new SheetsRegistry() const registry = new SheetsRegistry()
const generateId = createGenerateId() const generateId = createGenerateId()
const originalRenderPage = ctx.renderPage const originalRenderPage = ctx.renderPage
......
...@@ -12,7 +12,7 @@ const useStyles = createUseStyles({ ...@@ -12,7 +12,7 @@ const useStyles = createUseStyles({
}, },
}) })
function Index() { export default function IndexPage() {
const classes = useStyles() const classes = useStyles()
return ( return (
...@@ -23,5 +23,3 @@ function Index() { ...@@ -23,5 +23,3 @@ function Index() {
</div> </div>
) )
} }
export default Index
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"moduleResolution": "node",
"module": "esnext",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
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