Next.js · Middle · Question 2 of 75
What does <form action={createPost}> with a Server Action give you compared to onSubmit + fetch?
- ✓Correct answer: The form works even before JS loads (progressive enhancement), with no API route
- 2The form submits faster thanks to a persistent WebSocket connection
- 3Form data is automatically validated against the database schema
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.