Skip to content
Discussion options

You must be logged in to vote

Hi there! 👋

This is a great question! The transition from useFormState to useActionState is one of the most common friction points in the Next.js 15 upgrade, but the new API is actually cleaner once you get the boilerplate down.

Here is a robust pattern using Zod for validation and TypeScript for type-safe error handling.

Step 1: Define your State Type & Action

First, create your action. Note that we return a State object that includes both errors and a message.

// actions.ts
'use server'

import { z } from 'zod'

// 1. Define the Zod Schema
const subscribeSchema = z.object({
  email: z.string().email({ message: "Please enter a valid email address." }),
})

// 2. Define the State interface

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@devMosaic
Comment options

@Arjun-M
Comment options

@devMosaic
Comment options

Answer selected by devMosaic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants