Skip to content

Commit c6f65b2

Browse files
committed
Final de la clase del 6 de Junio
1 parent 86bcc04 commit c6f65b2

File tree

8 files changed

+93
-16
lines changed

8 files changed

+93
-16
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
type Beer = Record<string, any>;
3+
4+
const getBeerById = async (id: string): Promise<Beer> => {
5+
console.log("getBeerById", id);
6+
const response = await fetch(`https://api.punkapi.com/v2/beers/${id}`);
7+
const [beer] = await response.json();
8+
return beer;
9+
};
10+
11+
12+
type Props = {
13+
params: {
14+
beerId: string,
15+
}
16+
}
17+
export default async function Page({ params }: Props) {
18+
const { beerId } = params;
19+
const beer = await getBeerById(beerId);
20+
return <div>{beerId} - {beer.name}</div>
21+
}

2023-06-06/next1/app/beers/page.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Link from "next/link";
2+
3+
type Beer = Record<string, any>;
4+
5+
const loadBeers = async (): Promise<Array<Beer>> => {
6+
7+
const response = await fetch(`https://api.punkapi.com/v2/beers`);
8+
const beers = await response.json();
9+
return beers;
10+
};
11+
12+
export default async function Page() {
13+
const beers = await loadBeers();
14+
return (
15+
<div className="flex flex-col">
16+
{beers.map((beer) => (
17+
<Link key={beer.id} href={`/beers/${beer.id}`}>{beer.name}</Link>
18+
))}
19+
</div>
20+
);
21+
}

2023-06-06/next1/app/layout.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
import './globals.css'
2-
import { Inter } from 'next/font/google'
1+
import "./globals.css";
2+
import { Inter } from "next/font/google";
33

4-
const inter = Inter({ subsets: ['latin'] })
4+
const inter = Inter({ subsets: ["latin"] });
55

66
export const metadata = {
7-
title: 'Create Next App',
8-
description: 'Generated by create next app',
9-
}
7+
title: "Create Next App",
8+
description: "Generated by create next app",
9+
};
1010

11-
export default function RootLayout({
12-
children,
13-
}: {
14-
children: React.ReactNode
15-
}) {
11+
type Props = {
12+
children: React.ReactNode;
13+
};
14+
export default function RootLayout({ children }: Props) {
1615
return (
1716
<html lang="en">
18-
<body className={inter.className}>{children}</body>
17+
<head></head>
18+
<body className={inter.className}>
19+
<header className="border bg-red-200">Este es el header del <code>RootLayout</code></header>
20+
{children}
21+
</body>
1922
</html>
20-
)
23+
);
2124
}

2023-06-06/next1/app/page.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import Link from "next/link";
2+
import Title from "./primera/Title";
13

2-
export default function Home() {
4+
export default function Page() {
35
return (
4-
<main className="p-3">
5-
<h1 className="font-bold text-2xl">Este es mi primer proyecto NextJS (13.2)</h1>
6+
<main className="p-3 flex flex-col">
7+
<Title />
8+
<Link href="/primera">Vete a primera</Link>
9+
<Link href="/beers">Lista de Cervezas</Link>
610
</main>
711
)
812
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Title() {
2+
return (
3+
<h1 className="font-bold text-2xl">
4+
Este es mi primer proyecto NextJS
5+
</h1>
6+
);
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
type Props = {
3+
children: React.ReactNode;
4+
}
5+
export default function Layout({ children }: Props) {
6+
return <div>
7+
{children}
8+
<aside>Este es el layout de <code>/primera</code></aside>
9+
</div>
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return <div>Esta es la mini</div>
3+
}

2023-06-06/next1/app/primera/page.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Link from "next/link";
2+
3+
export default function Page() {
4+
return <div className="p-3">
5+
<h1 className="text-2xl font-bold">Primera</h1>
6+
<Link href="/primera/mini">Vete a mini</Link>
7+
</div>
8+
}

0 commit comments

Comments
 (0)