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
SOURCE CODE·typescript
"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." }; }
UTF-8 · Tab indentationStandard Strict Parsing
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

#TypistAccWPM
1Yonatan Ashenafi100%289
2Mohammed Khalid90.64%74
3Mohammed Khalid85.71%70
4Mishaal82.54%42
5Mishaal82.54%42