What are Server Actions in React 19?
Assesses fundamental understanding of React conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
Server Actions allow you to call server-side functions directly from client components without writing API endpoints.
#### Basic Server Action
// app/actions.js
'use server'
export async function createPost(formData) {
const title = formData.get('title');
const content = formData.get('content');
const post = await db.posts.create({
title,
content,
userId: await getCurrentUser()
});
revalidatePath('/posts');
redirect(`/posts/${post.id}`);
}
#### Using in Forms
// app/new-post.jsx
import { createPost } from './actions';
export default function NewPost() {
return (
<form action={createPost}>
<input name="title" required />
<textarea name="content" required />
<button type="submit">Create Post</button>
</form>
);
}
#### With useFormState for Loading States
'use client'
import { useFormState } from 'react-dom';
import { createPost } from './actions';
export default function NewPost() {
const [state, formAction] = useFormState(createPost, { message: '' });
return (
<form action={formAction}>
<input name="title" required />
<textarea name="content" required />
<button type="submit">Create Post</button>
{state.message && <p>{state.message}</p>}
</form>
);
}
#### Progressive Enhancement
Server Actions work even if JavaScript is disabled!
// This form works without JavaScript
<form action={serverAction}>
<input name="email" type="email" />
<button>Subscribe</button>
</form>
#### Security
- Automatically CSRF protected
- Always run on server (never exposed to client)
- Can use server-only packages safely
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.