Skip to content

Commit e533a6e

Browse files
committed
init
1 parent 376bf27 commit e533a6e

File tree

13 files changed

+440
-323
lines changed

13 files changed

+440
-323
lines changed

app/client/page.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use client'
2+
3+
import { useEffect } from 'react'
4+
5+
export default function Client(props) {
6+
console.log('🚀 ~ file: page.js:6 ~ props')
7+
8+
useEffect(() => {
9+
console.log('============ client page =================')
10+
})
11+
if (props.children) {
12+
return (
13+
<>
14+
<h1>client Page</h1>
15+
{props.children}
16+
</>
17+
)
18+
}
19+
return <h1>client Page</h1>
20+
}
21+
22+
// getServerSideProps is not supported
23+
24+
// export async function getServerSideProps() {
25+
// return { props: { data: [{ key: 'value', key1: 'value1', key2: 'value2' }] } }
26+
// }

app/components/home.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default function Home({ data }) {
2+
console.log('🚀 ~ app => components => Home (server component)')
3+
4+
if (!data) {
5+
return <>loading...</>
6+
}
7+
8+
return (
9+
<div>
10+
{data.map((game, index) => {
11+
return (
12+
<div key={game?.id}>
13+
<h1>{game?.name}</h1>
14+
<h3>{game?.genre}</h3>
15+
</div>
16+
)
17+
})}
18+
</div>
19+
)
20+
}

app/item/[id]/page.js

-19
This file was deleted.

app/item/not-found.js

-3
This file was deleted.

app/mix/page.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Client from '../client/page'
2+
import Server from '../server/page'
3+
4+
export default function MixMatchPage() {
5+
console.log('🚀 ~ file: page.js:5 ~ MixMatchPage')
6+
return (
7+
<div>
8+
<h1>Mix Pages</h1>
9+
<div className="box-blue">
10+
<Client>
11+
<Server />
12+
</Client>
13+
</div>
14+
</div>
15+
)
16+
}

app/news/[page]/page.js

-22
This file was deleted.

app/server/page.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Home from "../components/home"
2+
3+
async function getData() {
4+
const res = await fetch(
5+
`https://5fbc07c3c09c200016d41656.mockapi.io/api/v1/games`
6+
)
7+
8+
if (!res.ok) {
9+
throw new Error('Failed to fetch data')
10+
}
11+
12+
console.log('🚀 fetch on server data')
13+
return res.json()
14+
}
15+
16+
export default async function Server() {
17+
console.log('============== Server page ======================')
18+
const data = await getData()
19+
20+
return (
21+
<>
22+
<h1>Server Page</h1>
23+
<Home data={data} />
24+
</>
25+
)
26+
}

components/header.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Link from 'next/link'
55
import styles from './header.module.css'
66

77
export default function Header() {
8+
console.log('🚀 ~ file: header.js:8 ~ Header')
89
return (
910
<header className={styles.header}>
1011
<div className={styles.left}>

next.config.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
const nextConfig = {
22
experimental: {
33
appDir: true
44
},
@@ -11,3 +11,9 @@ module.exports = {
1111
]
1212
}
1313
}
14+
15+
const withBundleAnalyzer = require('@next/bundle-analyzer')({
16+
enabled: process.env.ANALYZE === 'true'
17+
})
18+
19+
module.exports = withBundleAnalyzer(nextConfig)

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
2-
"packageManager": "[email protected]",
32
"scripts": {
43
"dev": "next dev",
54
"build": "next build",
5+
"build:analyze": "ANALYZE=true next build",
66
"start": "next start"
77
},
88
"dependencies": {
9+
"@next/bundle-analyzer": "^13.1.6",
910
"ms": "2.1.3",
1011
"next": "^13.1.0",
1112
"react": "^18.3.0-next",

pages/index.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Client from '../app/client/page'
2+
import Home from '../app/components/home'
3+
4+
export default function Page({ data }) {
5+
console.log('🚀 pages => index.js')
6+
7+
return (
8+
<>
9+
<h1>Client component (getServerSideProps)</h1>
10+
<Client>
11+
<Home data={data} />
12+
</Client>
13+
</>
14+
)
15+
}
16+
17+
export async function getServerSideProps() {
18+
const res = await fetch(
19+
`https://5fbc07c3c09c200016d41656.mockapi.io/api/v1/games`
20+
)
21+
22+
const data = await res.json()
23+
24+
return { props: { data } }
25+
}

0 commit comments

Comments
 (0)