File tree Expand file tree Collapse file tree 8 files changed +93
-16
lines changed Expand file tree Collapse file tree 8 files changed +93
-16
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
- import ' ./globals.css'
2
- import { Inter } from ' next/font/google'
1
+ import " ./globals.css" ;
2
+ import { Inter } from " next/font/google" ;
3
3
4
- const inter = Inter ( { subsets : [ ' latin' ] } )
4
+ const inter = Inter ( { subsets : [ " latin" ] } ) ;
5
5
6
6
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
+ } ;
10
10
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 ) {
16
15
return (
17
16
< 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 >
19
22
</ html >
20
- )
23
+ ) ;
21
24
}
Original file line number Diff line number Diff line change
1
+ import Link from "next/link" ;
2
+ import Title from "./primera/Title" ;
1
3
2
- export default function Home ( ) {
4
+ export default function Page ( ) {
3
5
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 >
6
10
</ main >
7
11
)
8
12
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ export default function Page ( ) {
2
+ return < div > Esta es la mini</ div >
3
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments