Skip to content

Commit a982136

Browse files
committed
serverFunctionの例
1 parent c4b38a7 commit a982136

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

app/[docs_id]/chatForm.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use client";
2+
3+
import { hello } from "./chatServer";
4+
5+
export function ChatForm() {
6+
return <button className="btn" onClick={hello}>あああ</button>
7+
}

app/[docs_id]/chatServer.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use server";
2+
3+
export async function hello() {
4+
console.log("hello, world");
5+
}

app/[docs_id]/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { notFound } from "next/navigation";
22
import { readFile } from "node:fs/promises";
33
import { join } from "node:path";
44
import Markdown, { Components } from "react-markdown";
5+
import { ChatForm } from "./chatForm";
56

67
export default async function Page({
78
params,
@@ -24,6 +25,7 @@ export default async function Page({
2425
return (
2526
<div className="p-4">
2627
<Markdown components={components}>{mdContent}</Markdown>
28+
<ChatForm />
2729
</div>
2830
);
2931
}

app/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export default function Home() {
2-
return <div className="p-4">This is root page</div>;
2+
return <div className="p-4">
3+
This is root page
4+
</div>;
35
}

0 commit comments

Comments
 (0)