0Pricing
React Academy · Lesson

Server Actions in React 19 and Next.js

Understand how Server Actions execute on the server, close over server context, and return data to the client.

Server Actions in React 19 and Next.js is a free React Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the React Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Are Server Actions

Server Actions are async functions that execute on the server, not in the browser. They are marked with the 'use server' directive placed at the top of the file or at the top of the function body, signaling to the framework that this function must never run on the client side.

Server Context Access

Because Server Actions run on the server, they have access to the full server context: database connections, environment secrets, session data, and filesystem resources. This is fundamentally different from client components, which can only access what the browser exposes.

HTTP Transport Under the Hood

When a client component calls a Server Action, Next.js automatically makes an HTTP POST request to a special RSC endpoint. The framework handles all the serialization of arguments and the transport layer, so you never write fetch() calls manually for these mutations.

No API Route Needed

Server Actions replace the need for API routes in many mutation scenarios. The action itself is the endpoint — you define the logic once as a server function and call it directly from the client component as if it were a local function.

React 19 First-Class Feature

Server Actions were initially a Next.js-specific concept, but React 19 elevates them to a first-class React feature. This means bundlers and frameworks other than Next.js can implement the same pattern following the React specification.

Stability and Availability

Server Actions are experimental in React 19 RC but have been stable in Next.js 14+ App Router since their introduction. If you are building a production application today with Next.js App Router, Server Actions are a fully supported and recommended pattern.

Security: Secrets Stay on the Server

One of the most important security properties of Server Actions is that secrets never reach the browser. Environment variables like database passwords and API keys used inside a Server Action are never included in the client bundle, because the function body is never sent to the browser.

Forms and Server Actions

HTML form elements accept a Server Action directly via the action attribute: <form action={myServerAction}>. React intercepts the form submission and calls the Server Action with the form data, enabling server-side mutation without any client-side JavaScript plumbing.

Request and Response Cycle

When a Server Action is triggered, React serializes the action arguments into a POST request body. The server deserializes them, executes the function, serializes the return value, and sends it back. Only serializable values (strings, numbers, arrays, plain objects) can cross the boundary.

Defining a Server Action

You can define a Server Action at the module level in a file with 'use server' at the top, or inline inside a Server Component by placing 'use server' at the top of the async function. Both approaches produce the same result: a server-only callable function.

Calling from Client Components

Client components import and call Server Actions just like regular async functions. The calling syntax is identical to a local async function call, but the execution happens entirely on the server. This abstraction keeps client components clean and free of fetch boilerplate.

Security Model Question

Which of the following best describes the security model of Server Actions?

Lesson Recap

Server Actions are async server-side functions marked with 'use server'. They close over server context like database connections and environment secrets. Next.js handles the HTTP transport automatically, and React 19 makes them a framework-agnostic feature. Forms can use them directly via the action attribute, and secrets inside them never reach the browser.

Frequently asked questions

Is the “Server Actions in React 19 and Next.js” lesson free?

Yes — the full text of “Server Actions in React 19 and Next.js” is free to read here on the web, and the React Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the React Academy course, upgrade to CoddyKit PRO.

What will I learn in “Server Actions in React 19 and Next.js”?

Understand how Server Actions execute on the server, close over server context, and return data to the client. You practise React Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start React Academy?

No prior experience is required. React Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Server Actions in React 19 and Next.js” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this React Academy lesson?

Yes. Every React Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Server Actions in React 19 and Next.js
  2. Form Actions: Replacing API Routes for Mutations
  3. useActionState and useFormStatus
  4. Progressive Enhancement with Server Actions
← Back to React Academy