Skip to content

Commit b1a0077

Browse files
committedJan 30, 2024
refactor(example): directly import homepage Server Action in Client Component
1 parent e6e4e44 commit b1a0077

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed
 

‎packages/example-app/src/app/login-form.tsx

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
"use client";
22

33
import { useState } from "react";
4-
import type { loginUser } from "./login-action";
4+
import { loginUser } from "./login-action";
55

6-
type Props = {
7-
login: typeof loginUser; // infer types with `typeof`
8-
};
9-
10-
const LoginForm = ({ login }: Props) => {
6+
const LoginForm = () => {
117
const [result, setResult] = useState(
128
"fill in form and click on the log in button"
139
);
@@ -22,7 +18,7 @@ const LoginForm = ({ login }: Props) => {
2218
username: string;
2319
password: string;
2420
};
25-
const res = await login(input); // this is the typesafe action called from client
21+
const res = await loginUser(input); // this is the typesafe action called from client
2622
setResult(JSON.stringify(res, null, 1));
2723
}}>
2824
<input

‎packages/example-app/src/app/page.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Link from "next/link";
2-
import { loginUser } from "./login-action";
32
import LoginForm from "./login-form";
43

54
export const metadata = {
@@ -13,9 +12,9 @@ export default function Home() {
1312
<Link href="/hook">Go to /hook</Link>
1413
<Link href="/optimistic-hook">Go to /optimistic-hook</Link>
1514
<Link href="/form">Go to /form</Link>
15+
<Link href="/nested-schema">Go to /nested-schema</Link>
1616
<h1>Action without auth</h1>
17-
{/* Pass the typesafe mutation to Client Component */}
18-
<LoginForm login={loginUser} />
17+
<LoginForm />
1918
</>
2019
);
2120
}

0 commit comments

Comments
 (0)
Please sign in to comment.