From 0863f2d22d4d9930ca825a192d840806190bb1e6 Mon Sep 17 00:00:00 2001 From: unsivil Date: Mon, 24 Feb 2025 10:08:05 -0700 Subject: [PATCH 1/2] more starting code fixes --- .../ClientDemo.js | 12 ++++++++++ .../DataFetchingDemo.js | 22 +++++++++++++++++++ .../RSCDemo.js | 14 ++++++++++++ .../dummy-data.json | 4 ++++ 4 files changed, 52 insertions(+) create mode 100644 attachments/25b RSC, Suspense, Server Actions/ClientDemo.js create mode 100644 attachments/25b RSC, Suspense, Server Actions/DataFetchingDemo.js create mode 100644 attachments/25b RSC, Suspense, Server Actions/RSCDemo.js create mode 100644 attachments/25b RSC, Suspense, Server Actions/dummy-data.json diff --git a/attachments/25b RSC, Suspense, Server Actions/ClientDemo.js b/attachments/25b RSC, Suspense, Server Actions/ClientDemo.js new file mode 100644 index 000000000..f53126891 --- /dev/null +++ b/attachments/25b RSC, Suspense, Server Actions/ClientDemo.js @@ -0,0 +1,12 @@ +export default function ClientDemo({ children }) { + console.log('ClientDemo rendered'); + return ( +
+

A React Client Component

+

+ Will be rendered on the client AND the server. +

+ {children} +
+ ); +} diff --git a/attachments/25b RSC, Suspense, Server Actions/DataFetchingDemo.js b/attachments/25b RSC, Suspense, Server Actions/DataFetchingDemo.js new file mode 100644 index 000000000..f7518f5c5 --- /dev/null +++ b/attachments/25b RSC, Suspense, Server Actions/DataFetchingDemo.js @@ -0,0 +1,22 @@ +import fs from 'node:fs/promises'; + +export default async function DataFetchingDemo() { + const data = await fs.readFile('dummy-db.json', 'utf-8'); + const users = JSON.parse(data); + + return ( +
+

RSC with Data Fetching

+

+ Uses async / await for data fetching. +

+ +
+ ); +} diff --git a/attachments/25b RSC, Suspense, Server Actions/RSCDemo.js b/attachments/25b RSC, Suspense, Server Actions/RSCDemo.js new file mode 100644 index 000000000..088262ebb --- /dev/null +++ b/attachments/25b RSC, Suspense, Server Actions/RSCDemo.js @@ -0,0 +1,14 @@ +export default async function RSCDemo() { + console.log('RSCDemo rendered'); + return ( +
+

A React Server Component

+

+ Will ONLY be rendered on the server or at build time. +

+

+ NEVER on the client-side! +

+
+ ); +} diff --git a/attachments/25b RSC, Suspense, Server Actions/dummy-data.json b/attachments/25b RSC, Suspense, Server Actions/dummy-data.json new file mode 100644 index 000000000..f5a7d4b1e --- /dev/null +++ b/attachments/25b RSC, Suspense, Server Actions/dummy-data.json @@ -0,0 +1,4 @@ +[ + { "id": "u1", "name": "Max Schwarzmüller", "title": "Instructor" }, + { "id": "u2", "name": "Manuel Lorenz", "title": "Instructor" } +] From 40182ce3b2263cd16fa96f47496b3e371a9dab72 Mon Sep 17 00:00:00 2001 From: unsivil Date: Mon, 24 Feb 2025 10:14:04 -0700 Subject: [PATCH 2/2] typo in file name --- .../{dummy-data.json => dummy-db.json} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename attachments/25b RSC, Suspense, Server Actions/{dummy-data.json => dummy-db.json} (100%) diff --git a/attachments/25b RSC, Suspense, Server Actions/dummy-data.json b/attachments/25b RSC, Suspense, Server Actions/dummy-db.json similarity index 100% rename from attachments/25b RSC, Suspense, Server Actions/dummy-data.json rename to attachments/25b RSC, Suspense, Server Actions/dummy-db.json