Next.js · Middle · Question 2 of 75

What does <form action={createPost}> with a Server Action give you compared to onSubmit + fetch?

Explanation

A Server Action receives FormData directly, so you don't need a Route Handler and a client fetch. If the form is rendered by a server component, it submits even before hydration. You still write validation yourself (e.g. with Zod). Submission state is shown via useActionState or useFormStatus.

Further reading

Problem with a question

Next.js · Middle · question 2

Test yourself

Take the Next.js · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz