Server-side functions callable from the client without an API route.
Skip to solutionKEEP THE
hardFrontend
What are Server Actions in Next.js and how do they work?
842 views
01
Understand the problem
nextjsserver-actionsmutationsrsc
02
Attempt it yourself
Sketch your approach before reading the solution — that's what interviews test.
Nudge consolestandby
Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.
03
Study the solution
Server Actions are async functions marked 'use server' that run on the server and can be called from components/forms directly — Next.js creates an RPC endpoint under the hood. They handle mutations (DB writes, revalidation) without you writing an API route.
Solution ready — 2 min read
Classified // press E to declassify
04
Read the code
A Server Action mutating + revalidating
// app/actions.ts
'use server';
import { revalidatePath } from 'next/cache';
export async function addTodo(formData: FormData) {
const title = String(formData.get('title'));
await db.todo.create({ data: { title } }); // runs on the server
revalidatePath('/todos'); // refresh the list
}05
Join the discussion
Discussion (0)
Sign in to join the discussion.
No responses yet. Be the first to share what you think.
Transmission complete // awaiting log
KEEP THE
STREAK ALIVE.
Dossier 79 of 95 decoded in the Next.js track. One more won't hurt.