hardFrontend

What are Server Actions and the `"use server"` directive in React 19?

296 views
01

Understand the problem

Server functions callable from the client, integrated with forms.

reactreact-19rscserver-actions
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Stuck? AI Nudge Available

Get a conceptual hint to guide your logic without spoiling the final implementation.

03

Study the solution

The solution is waiting

Give it an honest attempt first — then compare your thinking with the full walkthrough.

04

Read the code

Server Action + form (needs an RSC framework)
// app/actions.js
'use server';
export async function addTodo(formData) {
  // runs ONLY on the server — safe to touch the DB directly
  await db.todo.create({ data: { text: formData.get('text') } });
}

// app/TodoForm.jsx (a client component)
import { addTodo } from './actions';

export default function TodoForm() {
  // The server function is passed straight to the form's action.
  return (
    <form action={addTodo}>
      <input name="text" />
      <button>Add</button>
    </form>
  );
}
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.