-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(examples): add react-19 example
- Loading branch information
Showing
7 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |