React / Next.js

Next.js Server Actions

Server Actions, useFormState, useFormStatus, mutations, progressive enhancement, revalidation

20 interview questionsยท
Mid-Level
1

What is a Server Action in Next.js?

Answer

A Server Action is an asynchronous function that executes only on the server and can be called directly from Client or Server components. It handles data mutations (POST, PUT, DELETE) without creating an explicit API route. Server Actions simplify code by avoiding the duplication of API route + client-side fetch call.

2

How to declare a Server Action in a separate file?

Answer

To create a Server Action in a separate file, add the 'use server' directive at the top of the file and export async functions. This approach is recommended for reusability and separation of concerns. Functions can then be imported into any Client or Server component.

3

What is the difference between a Server Action and an API route?

Answer

Server Actions are callable directly from components without creating an explicit REST endpoint, while API routes require an HTTP call (fetch). Server Actions simplify code by avoiding route + client call duplication. They're optimal for simple mutations, but API routes remain useful for public endpoints or webhooks.

4

How to use a Server Action in an HTML form?

5

What type of data does a Server Action receive from a form?

+17 interview questions

Master React / Next.js for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free