25 lines
750 B
TypeScript
25 lines
750 B
TypeScript
"use client";
|
|
|
|
import { useFormState } from "react-dom";
|
|
import { addNote, signOut, type ActionResult } from "../actions";
|
|
|
|
const initialState: ActionResult = {};
|
|
|
|
export function NoteForm() {
|
|
const [state, action] = useFormState(addNote, initialState);
|
|
|
|
return (
|
|
<div style={{ display: "grid", gap: 12 }}>
|
|
<form action={action} style={{ display: "flex", gap: 8 }}>
|
|
<input name="body" placeholder="New note" required style={{ flex: 1 }} />
|
|
<button type="submit">Add</button>
|
|
</form>
|
|
{state.error && <p style={{ color: "crimson" }}>{state.error}</p>}
|
|
{state.message && <p>{state.message}</p>}
|
|
<form action={signOut}>
|
|
<button type="submit">Sign out</button>
|
|
</form>
|
|
</div>
|
|
);
|
|
}
|