typescriptNext.jsintermediate
Next.js Typed Server Action
Server Action with revalidatePath and safe response schema in Next.js
By ApeType Staff·22 lines·541 characters·1,420 total attempts
"use server";
import { revalidatePath } from "next/cache";
interface MutationState {
success: boolean;
message?: string;
}
export async function submitSnippet(
prevState: MutationState,
formData: FormData
): Promise<MutationState> {
const title = formData.get("title")?.toString().trim();
const code = formData.get("code")?.toString().trim();
if (!title || !code) {
return { success: false, message: "Title and code are required." };
}
revalidatePath("/snippets");
return { success: true, message: "Snippet saved successfully." };
}
TRANSCRIBE
Ready when you are.
Test your muscle memory and transcription speed against this exact snippet.
Start Typing
Tip: Press Esc anytime to restart
Best runs on this snippet
| # | Typist | Acc | WPM |
|---|---|---|---|
| 1 | Yonatan Ashenafi | 100% | 289 |
| 2 | Mohammed Khalid | 90.64% | 74 |
| 3 | Mohammed Khalid | 85.71% | 70 |
| 4 | Mishaal | 82.54% | 42 |
| 5 | Mishaal | 82.54% | 42 |