Skip to content

Commit a2e3b27

Browse files
ariannargesisamcx
andauthored
Migrate the with-jotai example from page router to app router (#63390)
## Migrate the with-jotai example from page router to app router Please if it needs further updates, Let me know! Happy to contribute --------- Co-authored-by: Sam Ko <[email protected]>
1 parent e12535c commit a2e3b27

File tree

7 files changed

+40
-34
lines changed

7 files changed

+40
-34
lines changed

examples/with-jotai/app/layout.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Provider } from "jotai";
2+
import { Metadata } from "next";
3+
4+
export const metadata: Metadata = {
5+
icons: "/favicon.ico",
6+
};
7+
8+
export default function RootLayout({
9+
children,
10+
}: {
11+
children: React.ReactNode;
12+
}) {
13+
return (
14+
<html lang="en">
15+
<body>
16+
<Provider>{children}</Provider>
17+
</body>
18+
</html>
19+
);
20+
}

examples/with-jotai/pages/index.tsx renamed to examples/with-jotai/app/page.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import Head from "next/head";
21
import Image from "next/image";
32
import styles from "../styles/Home.module.css";
3+
import "../styles/globals.css";
44
import Canvas from "../components/Canvas";
5+
import { Metadata } from "next";
6+
7+
export const metadata: Metadata = {
8+
title: "with-jotai",
9+
description: "Generated by create next app",
10+
};
511

612
export default function Home() {
713
return (
814
<div className={styles.container}>
9-
<Head>
10-
<title>with-jotai</title>
11-
<meta name="description" content="Generated by create next app" />
12-
<link rel="icon" href="/favicon.ico" />
13-
</Head>
1415
<h1 className={styles.title}>With Jotai example</h1>
1516
<main className={styles.main}>
1617
<Canvas />

examples/with-jotai/components/Canvas.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use client";
2+
13
import { atom, useAtom } from "jotai";
24

35
type Point = [number, number];

examples/with-jotai/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
"start": "next start"
77
},
88
"dependencies": {
9-
"jotai": "1.7.3",
9+
"jotai": "2.7.1",
1010
"next": "latest",
1111
"react": "18.2.0",
1212
"react-dom": "18.2.0"
1313
},
1414
"devDependencies": {
15+
"@types/node": "20.11.28",
1516
"@types/react": "17.0.16",
1617
"eslint": "7.32.0",
1718
"eslint-config-next": "11.0.1",

examples/with-jotai/pages/_app.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

examples/with-jotai/pages/api/hello.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/with-jotai/tsconfig.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
43
"lib": ["dom", "dom.iterable", "esnext"],
54
"allowJs": true,
65
"skipLibCheck": true,
76
"strict": true,
87
"forceConsistentCasingInFileNames": true,
98
"noEmit": true,
9+
"incremental": true,
1010
"esModuleInterop": true,
1111
"module": "esnext",
1212
"moduleResolution": "node",
1313
"resolveJsonModule": true,
1414
"isolatedModules": true,
15-
"jsx": "preserve"
15+
"jsx": "preserve",
16+
"plugins": [
17+
{
18+
"name": "next"
19+
}
20+
],
21+
"strictNullChecks": true
1622
},
17-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
23+
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
1824
"exclude": ["node_modules"]
1925
}

0 commit comments

Comments
 (0)