Skip to content

Commit 2ef98cc

Browse files
committed
wip(useActionState): add new FormComponent
1 parent 62f0fe1 commit 2ef98cc

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use server";
2+
3+
import { useActionState } from "react";
4+
5+
async function handler(previousState: number, data: FormData) {
6+
console.log({ data })
7+
return previousState + 1;
8+
}
9+
10+
export function FormComponent() {
11+
const [state, formActionHandler] = useActionState(handler, 0);
12+
13+
return (
14+
<>
15+
<div className="state">{state}</div>
16+
<form action={formActionHandler} method="post">
17+
<button>Submit</button>
18+
</form>
19+
</>
20+
);
21+
}

0 commit comments

Comments
 (0)