Skip to content
Back to Mastery Path
Interactions

Form Handling

Next.js simplifies forms by using Server Actions. You can handle submissions directly in your components without manual API endpoints.

Interactive Concept Walkthrough

Modern Form Architecture

Progressive Enhancement & FormData

React Form (Hydrated)
Server-Side Handler
fn: handleContact()
Waiting for stream...

Hydrated Mode: React will handle the submission, allowing for smooth loading states and client-side validation.

Editable Code Example
page.tsx
Editable Code Example
1export default function ContactForm() {
2  async function handleSubmit(formData: FormData) {
3    'use server'
4    const email = formData.get('email')
5    // Send email...
6  }
7
8  return (
9    <form action={handleSubmit}>
10      <input type="email" name="email" />
11      <button type="submit">Contact Me</button>
12    </form>
13  )
14}
Mental Model
Think of a mailbox. You put your letter (data) in the box, and the postman (Next.js) takes it straight to the server for you.
Why This Exists
To provide a seamless way to handle user input that works even if JavaScript is slow to load, improving accessibility and developer experience.
Critical Note
"Developers often confuse this pattern with traditional client React. Use the editable code example above to follow the walkthrough."