Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| web:framework:nextjs [2024/04/08 08:33] – jcheron | web:framework:nextjs [2026/04/08 07:25] (Version actuelle) – jcheron | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== NextJS====== | ====== NextJS====== | ||
| + | |||
| NextJS est un Framework FullStack basé sur ReactJS, côté serveur et côté client. | NextJS est un Framework FullStack basé sur ReactJS, côté serveur et côté client. | ||
| + | |||
| + | ===== Sommaire ===== | ||
| + | * [[web: | ||
| + | * [[web: | ||
| + | * [[web: | ||
| + | |||
| ===== Installation ===== | ===== Installation ===== | ||
| [[https:// | [[https:// | ||
| Ligne 28: | Ligne 35: | ||
| < | < | ||
| + | |||
| + | === Layout === | ||
| + | **app/ | ||
| + | |||
| + | ==== Routes api ==== | ||
| + | Création d'un mock de service backend : | ||
| + | |||
| + | <sxh ts> | ||
| + | // app/ | ||
| + | export async function GET() { | ||
| + | const projets = [ | ||
| + | { id: 1, titre: "Todo App", description: | ||
| + | { id: 2, titre: " | ||
| + | ]; | ||
| + | |||
| + | return Response.json(projets); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Accessible immédiatement sur http:// | ||
| ==== Recupération de données ==== | ==== Recupération de données ==== | ||
| Ligne 33: | Ligne 60: | ||
| === Côté serveur === | === Côté serveur === | ||
| - | == Server Side Rendering | + | == Page avec SSR == |
| <WRAP info round> | <WRAP info round> | ||
| Ligne 39: | Ligne 66: | ||
| </ | </ | ||
| - | < | + | < |
| + | export default async function EventsPage() { | ||
| + | const res = await fetch(" | ||
| + | const events = await res.json() | ||
| - | export default function Home({data}) { | ||
| return ( | return ( | ||
| - | <> | + | <div> |
| - | <UIList objects={data}/> | + | < |
| - | </ > | + | {events.map((e: |
| + | <div key={e.id}> | ||
| + | ))} | ||
| + | </div> | ||
| ) | ) | ||
| } | } | ||
| + | </ | ||
| - | export async function | + | == Variables dans l'url == |
| - | const res = await fetch(API_URL) | + | |
| - | const data = await res.json() | + | Structure : |
| - | return | + | <sxh bash; |
| - | | + | app/ |
| - | data | + | </ |
| - | } | + | |
| - | | + | Code : |
| + | <sxh ts; | ||
| + | type Props = { | ||
| + | params: { id: string } | ||
| + | } | ||
| + | |||
| + | export | ||
| + | const res = await fetch(`http:// | ||
| + | const event = await res.json() | ||
| + | |||
| + | | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | | ||
| + | ) | ||
| } | } | ||
| </ | </ | ||
| + | URL : ''/ | ||
| == Static Site Generation == | == Static Site Generation == | ||