next-server-actions

Implements validated Server Actions, form wiring, and API route patterns for Next.js App Router.

Updated Jan 12, 2026
One-click install
npx skills add https://github.com/brandonarbini/arbini.family --skill next-server-actions-brandonarbini
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: next-server-actions
Source: https://github.com/brandonarbini/arbini.family/tree/main/.agents/skills/next-server-actions
Command: npx skills add https://github.com/brandonarbini/arbini.family --skill next-server-actions-brandonarbini

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Next.js App Router mutations often end up with inconsistent validation, missing auth checks, opaque production errors, and forms that show no field feedback. This Skill defines a clear contract for Server Actions, validation schemas, and form wiring so mutations behave predictably. ## Core Features & Use Cases - Action contract enforcement: Every Server Action authenticates first, validates input with safeParse from a shared validations.ts schema, returns typed result objects instead of throwing, and invalidates cache tags after writes. - Form wiring patterns: Default useActionState with native <form action> for simple forms, react-hook-form with a shared schema resolver for complex forms, and useOptimistic for instant UI feedback. - API route discipline: api/route.ts stays a thin auth-plus-service wrapper, created only when a client component actually refetches data. - Use Case: When building a discount-code creation form, the Skill guides you to define a schema in validations.ts, write an action that returns { ok: false, fieldErrors } on failure, and render per-field errors directly from the action state. ## Quick Start Use the next-server-actions skill to write a Server Action with validation and wire it to a form using useActionState.

Frequently Asked Questions about next-server-actions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate form input in a Next.js Server Action?▼

Validate input with safeParse against a schema defined in a shared validations.ts file before any other logic. On failure, return a typed result object containing fieldErrors rather than throwing, so the client can display per-field messages.

When should I use react-hook-form vs useActionState in Next.js?▼

Use useActionState with a native form action for simple forms where pending state and returned field errors suffice. Reach for react-hook-form only with real client-side complexity like cross-field validation, dynamic field arrays, or wizard steps, sharing the same schema via a resolver.

Why does my Next.js form show no error message in production?▼

Thrown validation errors become an opaque production digest with no field detail. Return a typed error result from the action instead of throwing, and render field errors from the state returned by useActionState.

Can I call redirect() inside a try/catch in a Server Action?▼

No. redirect() and notFound() signal by throwing a special control-flow error that Next.js catches, so wrapping them in try/catch breaks navigation. Call redirect() after the successful write, outside any error handling.

Should Server Actions be used for reading data in Next.js?▼

No. Actions POST and dispatch sequentially, so using them as read fetchers serializes concurrent reads and loses HTTP cache semantics. Use GET route handlers or server components calling cached data functions instead.