Skip to content

Commit

Permalink
docs(examples): add react-19 example
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblack committed Nov 6, 2024
1 parent 92102e9 commit 8dd5cda
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/react-19/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

const path = require('node:path')

module.exports = {
extends: ['plugin:@next/next/recommended'],
settings: {
next: {
rootDir: path.join(__dirname, 'src'),
},
},
rules: {
'react/react-in-jsx-scope': 'off',
},
}
5 changes: 5 additions & 0 deletions examples/react-19/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
24 changes: 24 additions & 0 deletions examples/react-19/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "example-react-19",
"version": "0.0.0",
"private": true,
"scripts": {
"clean": "rimraf .next",
"build": "next build",
"develop": "next",
"start": "next start",
"type-check": "tsc --noEmit"
},
"dependencies": {
"@primer/react": "37.3.0",
"next": "15.0.2",
"react": "19.0.0-rc-02c0e824-20241028",
"react-dom": "19.0.0-rc-02c0e824-20241028",
"styled-components": "5.x",
"typescript": "^5.6.3"
},
"devDependencies": {
"@next/eslint-plugin-next": "15.0.2",
"rimraf": "^5.0.5"
}
}
23 changes: 23 additions & 0 deletions examples/react-19/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {BaseStyles, ThemeProvider} from '@primer/react'
import {StyledComponentsRegistry} from './registry'

export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
}

export default function RootLayout({children}: {children: React.ReactNode}) {
return (
// Note: the focus-visible polyfill adds additional attributes to `html`
// that cause hydration mismatch errors
<html lang="en" suppressHydrationWarning>
<body>
<StyledComponentsRegistry>
<ThemeProvider>
<BaseStyles>{children}</BaseStyles>
</ThemeProvider>
</StyledComponentsRegistry>
</body>
</html>
)
}
5 changes: 5 additions & 0 deletions examples/react-19/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Button} from '@primer/react'

export default function IndexPage() {
return <Button>Hello world</Button>
}
24 changes: 24 additions & 0 deletions examples/react-19/src/app/registry.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use client'

import {useServerInsertedHTML} from 'next/navigation'
import React, {useState} from 'react'
import {ServerStyleSheet, StyleSheetManager} from 'styled-components'

/**
* @see https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components
*/
export function StyledComponentsRegistry({children}: React.PropsWithChildren) {
// Only create stylesheet once with lazy initial state
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())

useServerInsertedHTML(() => {
const styles = styledComponentsStyleSheet.getStyleElement()
styledComponentsStyleSheet.instance.clearTag()
return <>{styles}</>
})

if (typeof window !== 'undefined') return <>{children}</>

return <StyleSheetManager sheet={styledComponentsStyleSheet.instance}>{children}</StyleSheetManager>
}
35 changes: 35 additions & 0 deletions examples/react-19/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"target": "ES2017"
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}

0 comments on commit 8dd5cda

Please sign in to comment.