MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Form Handling with useActionState, useFormStatus & Zod Validation0%
Study Materials
Next.js 15Progress 0%
1.1Next.js 15 Overview & App Router vs Pages Router Architecture1.2Core File Conventions: page.tsx, layout.tsx, template.tsx & not-found.tsx1.3Dynamic Routes ([id]), Catch-All Routes ([...slug]) & Route Groups ((group))1.4Streaming UI with loading.tsx and Suspense Boundaries
3.1Server Actions ("use server"): Type-Safe Mutations Without API Endpoints3.2Form Handling with useActionState, useFormStatus & Zod Validation3.3On-Demand Cache Revalidation with revalidatePath and revalidateTag3.4Optimistic UI Updates with React useOptimistic Hook
HomeTutorialsNext.js 15Form Handling with useActionState, useFormStatus & Zod Validation
On-Demand Cache Revalidation with revalidatePath and revalidateTag

Form Handling with useActionState, useFormStatus & Zod Validation

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

Building professional forms in Next.js 15 requires combining React 19's useActionState (for managing action state and error responses), useFormStatus (for loading and pending states), and Zod (for type-safe schema validation).


1. The React 19 / Next.js 15 Form Stack

  • useActionState: Hook that wraps a Server Action to track return values, validation errors, and pending state across submissions.
  • useFormStatus: Hook that provides the pending status of a parent <form>, allowing buttons to display spinners during submission.
  • Zod Validation: Validates form fields on the server before database mutation.

2. Server Action with Zod Validation

1// app/actions/auth-actions.ts
2'use server';
3 
4import { z } from 'zod';
5 
6const signupSchema = z.object({
7 email: z.string().email('Invalid email address format'),
8 password: z.string().min(8, 'Password must be at least 8 characters long')
9});
10 
11export type ActionState = {
12 errors?: {
13 email?: string[];
14 password?: string[];
15 };
16 message?: string;
17};
18 
19export async function signupUser(prevState: ActionState, formData: FormData): Promise<ActionState> {
20 const result = signupSchema.safeParse({
21 email: formData.get('email'),
22 password: formData.get('password')
23 });
24 
25 if (!result.success) {
26 return {
27 errors: result.error.flatten().fieldErrors
28 };
29 }
30 
31 // Database registration logic...
32 return { message: 'Account successfully registered!' };
33}

3. The Client Form Component with useActionState

1// components/SignupForm.tsx
2'use client';
3 
4import { useActionState } from 'react';
5import { useFormStatus } from 'react-dom';
6import { signupUser, type ActionState } from '@/app/actions/auth-actions';
7 
8function SubmitButton() {
9 const { pending } = useFormStatus();
10 return (
11 <button
12 type="submit"
13 disabled={pending}
14 className="w-full bg-blue-600 text-white py-2 rounded disabled:bg-slate-400"
15 >
16 {pending ? 'Submitting...' : 'Sign Up'}
17 </button>
18 );
19}
20 
21export default function SignupForm() {
22 const initialState: ActionState = {};
23 const [state, formAction] = useActionState(signupUser, initialState);
24 
25 return (
26 <form action={formAction} className="max-w-md mx-auto space-y-4">
27 {state.message && <p className="text-green-600 font-medium">{state.message}</p>}
28 
29 <div>
30 <label className="block text-sm font-medium">Email</label>
31 <input name="email" type="email" className="w-full border p-2 rounded" />
32 {state.errors?.email && (
33 <p className="text-red-500 text-sm mt-1">{state.errors.email[0]}</p>
34 )}
35 </div>
36 
37 <div>
38 <label className="block text-sm font-medium">Password</label>
39 <input name="password" type="password" className="w-full border p-2 rounded" />
40 {state.errors?.password && (
41 <p className="text-red-500 text-sm mt-1">{state.errors.password[0]}</p>
42 )}
43 </div>
44 
45 <SubmitButton />
46 </form>
47 );
48}

Interactive Quiz• Knowledge Check

Multiple Choice Questions

Question 1
Which React 19 hook replaces the experimental useFormState in Next.js 15 for managing server action return states and errors?
Question 2
Where must the useFormStatus hook be called to accurately detect if a form submission is pending?
Question 3
What method on a Zod schema validates data without throwing exceptions, returning an object with { success: true, data } or { success: false, error }?
Question 4
What is the first argument passed to a Server Action when wired through useActionState?
Question 5
Why is server-side validation with Zod necessary even if the client form includes HTML5 required and type="email" attributes?

Next Lesson

On-Demand Cache Revalidation with revalidatePath and revalidateTag

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Server Actions ("use server"): Type-Safe Mutations Without API EndpointsOn-Demand Cache Revalidation with revalidatePath and revalidateTag

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Next.js 15 with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext